Hello ALL,
I know this is simple but I been working on this file for two days. I think I did fairly well up to the point where I completely when brain dead. I just did did something like this 3 weeks ago byt now I'm complely lost. I think I could have over did it for such that should be a simple operation i guest.
If the user enter "-1" the programs is suppose to exit from any point. I'm so deep down in the program that my only hope to exit is at the END of the program with -1 if i'm lucky. Could someone show me how to correct this.
"-1 to exit"
I could almost swear I had this down to a science just weeks ago. Goes to show, never mis-place or loss your work or examples. I'll be careful for now on! Too many OS's all at the same time and everything else to learn for.Code:#include <iostream>
using namespace std;
void compare_1 (int a);
void tryAgain (int a);
void main_2 (int a);
void compare_2 (int a);
void tryAgain_2 (int a);
void main_3 (int a);
void compare_3 (int a);
void tryAgain_3 (int a);
int num1;
int num2;
int main ()
{
int x=3,y=2;
num1 = x * y;
cout << num1 << endl;
do {
cout << "How much is 3 x 2 (-1 to exit): " << endl;
cout <<"? ";
cin >> num2;
compare_1 (num2);
} while (num2==-1);
cout << "That's all for now. Have a nice day! " << endl << endl;
return 0;
}
// ................................................ 1 1 1 1
// ................................................
void compare_1 (int a)
{
if (num1 == num2)
{
cout <<" Very good! " <<endl <<endl;
main_2 (a);
}
else tryAgain (a);
}
void tryAgain (int a)
{
cout << "Try again.\n";
main();
}
// ................................................ 2 2 2 2
// ................................................
void main_2 (int a)
{
int x=3,y=0;
num1 = x * y;
cout << num1 << endl;
do {
cout << "How much is 3 x 0 (-1 to exit): " << endl;
cout <<"? ";
cin >> num2;
compare_2 (num2);
} while (num2!=0);
// return 0;
}
void compare_2 (int a)
{
if (num1 == num2)
{
cout <<" Very good! " <<endl <<endl;
main_3 (a);
}
else tryAgain_2 (a);
}
void tryAgain_2 (int a)
{
cout << "Try again.\n";
main_2(a);
}
// ................................................ 3 3 3 3
// ................................................
void main_3 (int a)
{
int x= -1,y= -0;
num1 = x * y;
cout << num1 << endl;
do {
cout << "How much is 1 x 0 (-1 to exit): " << endl;
cout <<"? ";
cin >> num2;
compare_3 (num2);
} while (num2!=0);
// return 0;
}
void compare_3 (int a)
{
if (num1 == num2)
{
cout <<" Very good! " <<endl <<endl;
}
else tryAgain_3 (a);
}
void tryAgain_3 (int a)
{
cout << "Try again.\n";
main_3(a);
}
Thanks in advance