Need Help finishing school project.
My Code is the following:
# include <iostream>
# include <cmath>
# include <iomanip>
# include <ctime>
int randValue( int level );
int generateProblem( int option, int level );
void arithmetic( int option, int level );
void correctMessage();
void incorrectMessage();
using namespace std;
int main()
{
int level, option;
int num = rand();
srand((unsigned)time(0));
do
{
do
{
cout<<"Enter the grade-level: ";
cin>>level;
cout<<endl;
if (level < 1 || level > 3)
{
cout<<"Please Enter a level from 1 - 3\n"<<endl;
}
}while (level < 0 || level > 3);
do
{
cout<<"Select an arithmetic operation type: \n1. Addition \n2. Subtraction \n3. Multiplication \n4. Division \n5. Combination of 1 through 4 \n6. Select another level \n7. Exit \n\n";
cin>>option;
cout<<endl;
arithmetic (option, level);
}while (option >=1 && option <= 5);
}while (option = 6);
if (option = 7)
{
cout<<"Good Bye.\n"<<endl;
}
return 0;
}
int randValue (int level)
{
int num = rand();
switch (level)
{
case 1:
num = (rand() % 10);
break;
case 2:
num = (rand() % 100);
break;
case 3:
num = (rand() % 1000);
break;
}
return num;
}
int generateProblem (int option, int level)
{
int num1 = randValue(level);
int num2 = randValue(level);
int num = randValue(level);
num = (rand() %4);
switch (option)
{
case 1:
cout<<"How much is "<<num1<<" + "<<num2<<"?"<<endl;
return num1+num2;
break;
case 2:
cout<<"How much is "<<num1<<" - "<<num2<<"?"<<endl;
return num1-num2;
break;
case 3:
cout<<"How much is "<<num1<<" * "<<num2<<"?"<<endl;
return num1*num2;
break;
case 4:
if(num1 > 0 && num2 > 0)
{
cout<<"How much is "<<num1<<" / "<<num2<<"?"<<endl;
}
return num1/num2;
break;
case 5:
switch(num)
{
case 1:
cout<<"How much is "<<num1<<" + "<<num2<<"?"<<endl;
return num1+num2;
break;
case 2:
cout<<"How much is "<<num1<<" - "<<num2<<"?"<<endl;
return num1-num2;
break;
case 3:
cout<<"How much is "<<num1<<" * "<<num2<<"?"<<endl;
return num1*num2;
break;
case 4:
if(num1 > 0 && num2 > 0)
{
cout<<"How much is "<<num1<<" / "<<num2<<"?"<<endl;
}
return num1/num2;
break;
}
break;
}
return option;
}
void arithmetic (int option, int level)
{
int responce;
int result;
for (int i = 0; i < 5; i=i++)
{
result = generateProblem (option, level);
cin>>responce;
}
}
void correctMessage()
{
int num;
num = rand() %4;
switch(num)
{
case 0:
cout<<"Very Good!"<<endl;
break;
case 1:
cout<<"Excellent!"<<endl;
break;
case 2:
cout<<"Nice Work!"<<endl;
break;
case 3:
cout<<"Keep up the good work!"<<endl;
break;
}
}
void incorrectMessage()
{
int num;
num = (rand() %5);
switch (num)
{
case 0:
cout<<"No sorry."<<endl;
break;
case 1:
cout<<"Sorry, it's wrong."<<endl;
break;
case 2:
cout<<"Don't give up"<<endl;
break;
case 3:
cout<<"It's not the right answer"<<endl;
break;
}
}
And the Output should look like:
Enter the grade-level: 1
1
Select an arithmetic operation type:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Combination of 1 through 4
6. Select another level
7. Exit
1
How much is 3 + 7? 10
Very good!
How much is 1 + 0? 1
Nice work!
How much is 8 + 1? 9
Keep up the good work!
How much is 0 + 5? 5
Very good!
How much is 5 + 7? 12
Excellent!
You have 5 correct answers. You pass.
Select an arithmetic operation type:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Combination of 1 through 4
6. Select another level
7. Exit
5
How much is 4 + 0? 0
Don't give up!
How much is 3 * 8? 2
Sorry. It's wrong.
How much is 5 * 7? 12
No. Sorry.
How much is 0 + 5? 5
Excellent!
How much is 9 - 2? 7
Excellent!
You have 2 correct answers. You do not pass.
Please ask your instructor for extra help.
Select an arithmetic operation type:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Combination of 1 through 4
6. Select another level
7. Exit
6
Enter the grade-level: 2
1
Select an arithmetic operation type:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Combination of 1 through 4
6. Select another level
7. Exit
5
How much is 83 * 59? 1
Don't give up!
How much is 60 * 40? 2
Don't give up!
How much is 2465 / 85? 3
Sorry. It's wrong.
How much is 86 + 94? 180
Nice work!
How much is 90 * 34? 1
Don't give up!
You have 1 correct answers. You do not pass.
Please ask your instructor for extra help.
Select an arithmetic operation type:
1. Addtiion
2. Subtraction
3. Multiplication
4. Division
5. Combination of 1 through 4
6. Select another level
7. Exit
7
Good bye
*What I have problem with is the initial do while loops. its showing the "choose a level" when it shouldn't.
*after you hit 7 to exit the program you have to input another 5 numbers to exit.
* I don't really know how to implement the correctMessage/Wrong Message into the coding so that it displays correctly.
*sometimes after you choose the type of math problem it skips some.
*How to put the % of right and wrong answers so that it tells that he passed or he didn't. (75% of the problems to pass).
Sorry for the Long coding ._. but I really need the help in this one.
Thanks!

