#include <cstdlib> //for rand numbers #include <ctime> //for srand numbers #include <iostream> //for all programs using namespace std; int main() { int j; // this will int these variables int k; int num1; int num2; int product; int answer; int correctAnswer; // this will int these variables cout << "Welcome to the Times Table Tutor!"; cout << endl; cout << "This program will help you learn the multiplication tables."; cout << endl; cout << "You will have to answer 10 question correctly before the program will end."; cout << endl; for (num1 = 0; num2 <=10; num1++) { srand((unsigned)time(0)); j = 0 + rand() % 12; k = 0 + rand() % 12; cout << num1 * num2; product = num1 * num2; cin >> answer; cout << " Way to go, keep up the good work!"; while ( !(correctAnswer == answer)) // ask for the right answer { cout << "WRONG, Lets try it again"; cin >> answer; } cout << "Yea, your correct, I knew you could do it!"; // this should keep the loop going to complete the program } char userInput; cin >> userInput; return 0; }
I'll post the code so you can take a look at it. Just change the for loop to the desired number of itterations that you want or just use it as a template.This also was for my daughter.I another one for my older daugheter(11) that does multiplacation, subtraction, and addition, if your interested let me know and ill post the code for ya..anyway here it is.
int _tmain(int argc, _TCHAR* argv[]) { int product; int answer; int correct = 0; int wrong = 0; for ( int i = 1; i <= 3; i++ ) for( int j = 0; j <= 12; j++ ){ cout << "Chloie what is " << i << " X " << j << " = "; cin >> answer; product = i * j; if( answer == product ) { cout <<"Good Job Chloie!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad chloie....." << endl; cin.get(); return 0; }
Hey there!
Funny, I wrote the same thing awhile back when i first startedI'll post the code so you can take a look at it. Just change the for loop to the desired number of itterations that you want or just use it as a template.This also was for my daughter.I another one for my older daugheter(11) that does multiplacation, subtraction, and addition, if your interested let me know and ill post the code for ya..anyway here it is.
C++ Syntax (Toggle Plain Text)
int _tmain(int argc, _TCHAR* argv[]) { int product; int answer; int correct = 0; int wrong = 0; for ( int i = 1; i <= 3; i++ ) for( int j = 0; j <= 12; j++ ){ cout << "Chloie what is " << i << " X " << j << " = "; cin >> answer; product = i * j; if( answer == product ) { cout <<"Good Job Chloie!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad chloie....." << endl; cin.get(); return 0; }
Hope it helps
Hi,
I have modified your program to remove unused variables and unnecessary code. Hope this works out for you.
Regards,
vijay.
-----------------------------------------------------
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std ;
int main()
{
int j; // this will int these variables
int num1;
int num2;
int product;
int answer;
cout << "Welcome to the Times Table Tutor!";
cout << endl;
cout << "This program will help you learn the multiplication tables.";
cout << endl;
cout << "You will have to answer 10 question correctly before the program will end.";
cout << endl;
for (j = 1; j <= 10; j++) {
srand((unsigned)time(0));
num1 = 0 + rand() % 12;
num2 = 0 + rand() % 12;
cout << num1 << " * " << num2 << " = " ;
product = num1 * num2;
cin >> answer;
cout << " Way to go, keep up the good work!";
while ( !(product == answer)) // ask for the right answer
{
cout << "WRONG, Lets try it again ";
cin >> answer;
}
cout << "Yea, your correct, I knew you could do it!" << endl ;
}
return 0 ;
}
int _tmain(int argc, _TCHAR* argv[]) { int product; int sum; int answer; int correct = 0; int wrong = 0; int menu; do { cout << setw( 55 ) << "Math Tutor Progam For Lauren" << endl; cout << setw( 47 ) << "Author:Ben" << endl << endl; cout << setw( 49 ) << "*******Menu*******" << endl; cout << setw( 50 ) << "[1] Multiplacation " << endl; cout << setw( 44 ) << "[2] Addition " << endl; cout << setw( 47 ) << "[3] Subtraction " << endl; cout << setw( 40 ) << "[4] Exit " << endl << endl; cout <<"Please enter your choice: "; cin >> menu; switch ( menu ) { case 1: for ( int i = 1; i <= 12; i++ ) for( int j = 0; j <= 12; j++ ){ cout << "Lauren what is " << i << " X " << j << " = "; cin >> answer; product = i * j; if( answer == product ) { cout <<"Good Job Lauren!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad Lauren....." << endl; cin.get(); break; case 2: for ( int i = 1; i <= 12; i++ ) for( int j = 0; j <= 12; j++ ){ cout << "Lauren what is " << i << " + " << j << " = "; cin >> answer; sum = i + j; if( answer == sum ) { cout <<"Good Job Lauren!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" + " << j << " = " << sum << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad Lauren....." << endl; cin.get();; break; case 3: for ( int i = 12; i <= 22; i++ ) for( int j = 1; j <= 12; j++ ){ cout << "Lauren what is " << i << " - " << j << " = "; cin >> answer; sum = i - j; if( answer == sum ) { cout <<"Good Job Lauren!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" - " << j << " = " << sum << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad Lauren....." << endl; cin.get(); break; default: break; } }while ( menu != 4 ); return 0; }
At your request....here's the code.I havent changed it since i wrote it. I like to look back and see how I used to do things....hope this helps ya.
C++ Syntax (Toggle Plain Text)
int _tmain(int argc, _TCHAR* argv[]) { int product; int sum; int answer; int correct = 0; int wrong = 0; int menu; do { cout << setw( 55 ) << "Math Tutor Progam For Lauren" << endl; cout << setw( 47 ) << "Author:Ben" << endl << endl; cout << setw( 49 ) << "*******Menu*******" << endl; cout << setw( 50 ) << "[1] Multiplacation " << endl; cout << setw( 44 ) << "[2] Addition " << endl; cout << setw( 47 ) << "[3] Subtraction " << endl; cout << setw( 40 ) << "[4] Exit " << endl << endl; cout <<"Please enter your choice: "; cin >> menu; switch ( menu ) { case 1: for ( int i = 1; i <= 12; i++ ) for( int j = 0; j <= 12; j++ ){ cout << "Lauren what is " << i << " X " << j << " = "; cin >> answer; product = i * j; if( answer == product ) { cout <<"Good Job Lauren!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" X " << j << " = " << product << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad Lauren....." << endl; cin.get(); break; case 2: for ( int i = 1; i <= 12; i++ ) for( int j = 0; j <= 12; j++ ){ cout << "Lauren what is " << i << " + " << j << " = "; cin >> answer; sum = i + j; if( answer == sum ) { cout <<"Good Job Lauren!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" + " << j << " = " << sum << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad Lauren....." << endl; cin.get();; break; case 3: for ( int i = 12; i <= 22; i++ ) for( int j = 1; j <= 12; j++ ){ cout << "Lauren what is " << i << " - " << j << " = "; cin >> answer; sum = i - j; if( answer == sum ) { cout <<"Good Job Lauren!!!!!" << endl << endl; correct++; } else { cout << "Sorry " << i <<" - " << j << " = " << sum << endl << endl; wrong++; } } cout << "You got " << correct <<" right and " << wrong << " wrong" << endl<< endl; cout <<"Go get your dad Lauren....." << endl; cin.get(); break; default: break; } }while ( menu != 4 ); return 0; }
| DaniWeb Message | |
| Cancel Changes | |