K
Ken
I have a small program , wi tha menu (only option 1,2 and 6 are working
for now)
Something weird is happening, my array works to input all the data the user
puts in, but whebn I choose option 2, display, it always gives me 4202717
for the element number 1 in the array, While 0,2,3 .. are all ok.
It seems to be skipping number 1 in the array.
anyone ?
problem is in createTime() function
I am using visual c++
ken
#include <iostream>
#include <conio.h>
using namespace std;
class timeChange
{
public:
void createTime();
void display1();
private:
int t1, t2, i, j, a[] ;
};
inline void timeChange::createTime()
{
if (t1 >0)
{
cout<<" Enter a number 1: " <<endl;
cin>> t2;
i=0;
i = i + j;
do {
cout<<" before j: " << j <<endl;
cout<<" a: " << a <<endl;
cout<<" t2: " << t2 <<endl;
cout<<" before i: " << i <<endl;
i++;
a = t2;
j = i;
cout<<" j: " << j <<endl;
cout<<" a: " << a <<endl;
cout<<" t2: " << t2 <<endl;
cout<<" i: " << i <<endl;
}
while (t1 < 0);
}
else
{
cout<<" Enter a number 2: " <<endl;
cin>> t1;
i =0;
do {
a = t1;
cout<<" before j: " << j <<endl;
cout<<" t1: " << t1 <<endl;
cout<<" i: " << i <<endl;
cout<<" a: " << a <<endl;
cout<<" before i++: " << i <<endl;
i++;
j = i;
cout<<" j: " << j <<endl;
cout<<" t1: " << t1 <<endl;
cout<<" i: " << i <<endl;
}
while (t1 < 0);
} // end else
} //end void function
inline void timeChange::display1()
{
cout<<" Here it is: " << t1 <<endl;
for (int i=0; i<= j; i++)
{
cout<<"a: " << a << endl;
cout<<"i: " << i << endl;
}
}
/*inline void timeChange::diffTime()
inline void timeChange::substracTime()
inline void timeChange::addTime()
inline void timeChange::validateTime()
*/
void menu() //showing the menu for the 4 options
{ timeChange time;
int choice;
do {
cout << endl << endl;
cout << " Time Management System "<<endl;
cout << "============================================== "<<endl;
cout << " 1: Create a new time object "<<endl;
cout << " 2: Display all time object "<<endl;
cout << " 3: Calculate the difference between two times "<<endl;
cout << " 4: Substrat a number of seconds from a time "<<endl;
cout << " 5: Add a number of seconds to a time "<<endl;
cout << " 6: Quit "<<endl;
cout << "============================================== "<<endl;
cout << " Your choice please: ";
cin >> choice;
switch (choice)
{
case 1:
time.createTime();
//Calling function to convert seconds into hours
break;
case 2:
time.display1(); //Calling function to convert tome to seconds
break;
/* case 3:
time.diffTime();
break;
case 4:
time.substracTime(); //Calling function to subtract a time from seconds
break;
case 5:
time.addTime(); //Calling function to subtract a time from seconds
break;
*/ case 6: cout<<"Thank you for having used this system, Bye Bye!!!";
break;
default: cout<<"Error: Invalid option, Please try again" ;
}
} while (choice != 6);
}// end function menu
int main()
{
timeChange time;
menu();
getch();
return 0;
}
for now)
Something weird is happening, my array works to input all the data the user
puts in, but whebn I choose option 2, display, it always gives me 4202717
for the element number 1 in the array, While 0,2,3 .. are all ok.
It seems to be skipping number 1 in the array.
anyone ?
problem is in createTime() function
I am using visual c++
ken
#include <iostream>
#include <conio.h>
using namespace std;
class timeChange
{
public:
void createTime();
void display1();
private:
int t1, t2, i, j, a[] ;
};
inline void timeChange::createTime()
{
if (t1 >0)
{
cout<<" Enter a number 1: " <<endl;
cin>> t2;
i=0;
i = i + j;
do {
cout<<" before j: " << j <<endl;
cout<<" a: " << a <<endl;
cout<<" t2: " << t2 <<endl;
cout<<" before i: " << i <<endl;
i++;
a = t2;
j = i;
cout<<" j: " << j <<endl;
cout<<" a: " << a <<endl;
cout<<" t2: " << t2 <<endl;
cout<<" i: " << i <<endl;
}
while (t1 < 0);
}
else
{
cout<<" Enter a number 2: " <<endl;
cin>> t1;
i =0;
do {
a = t1;
cout<<" before j: " << j <<endl;
cout<<" t1: " << t1 <<endl;
cout<<" i: " << i <<endl;
cout<<" a: " << a <<endl;
cout<<" before i++: " << i <<endl;
i++;
j = i;
cout<<" j: " << j <<endl;
cout<<" t1: " << t1 <<endl;
cout<<" i: " << i <<endl;
}
while (t1 < 0);
} // end else
} //end void function
inline void timeChange::display1()
{
cout<<" Here it is: " << t1 <<endl;
for (int i=0; i<= j; i++)
{
cout<<"a: " << a << endl;
cout<<"i: " << i << endl;
}
}
/*inline void timeChange::diffTime()
inline void timeChange::substracTime()
inline void timeChange::addTime()
inline void timeChange::validateTime()
*/
void menu() //showing the menu for the 4 options
{ timeChange time;
int choice;
do {
cout << endl << endl;
cout << " Time Management System "<<endl;
cout << "============================================== "<<endl;
cout << " 1: Create a new time object "<<endl;
cout << " 2: Display all time object "<<endl;
cout << " 3: Calculate the difference between two times "<<endl;
cout << " 4: Substrat a number of seconds from a time "<<endl;
cout << " 5: Add a number of seconds to a time "<<endl;
cout << " 6: Quit "<<endl;
cout << "============================================== "<<endl;
cout << " Your choice please: ";
cin >> choice;
switch (choice)
{
case 1:
time.createTime();
//Calling function to convert seconds into hours
break;
case 2:
time.display1(); //Calling function to convert tome to seconds
break;
/* case 3:
time.diffTime();
break;
case 4:
time.substracTime(); //Calling function to subtract a time from seconds
break;
case 5:
time.addTime(); //Calling function to subtract a time from seconds
break;
*/ case 6: cout<<"Thank you for having used this system, Bye Bye!!!";
break;
default: cout<<"Error: Invalid option, Please try again" ;
}
} while (choice != 6);
}// end function menu
int main()
{
timeChange time;
menu();
getch();
return 0;
}