| | |
Math Tutoring Program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 3
Reputation:
Solved Threads: 0
I am trying to write a math tutoring program for students. A very basic outlay of ceretain components. This program should have the user select addition, subtraction, multiplication or division. user should also have the capeability to exit the program and quit it. I tried writing some code for this, but am having way to many issues. some criteria for this program should be
1 dispay what the user has inputted frm menu
2. generate 2 random #'s from 1-20
3. if user selects division, make sure divisor is not zero
4. display the #'s and accept the users answers from the keyboard on weather they perform addition subtraction mult, or division
5. calc the correct answer, compare the users answers to the answer calculated in the program
6. if user gets it correct display congratulations!
7. incorrect answers diplay incorrect!
8. after program operates display menu again, until users decides to end program by quitting.
Any form of help or snippets of code, or maybe what direction i should be heading in would be greatly apprecitated. Thanks in advance.
1 dispay what the user has inputted frm menu
2. generate 2 random #'s from 1-20
3. if user selects division, make sure divisor is not zero
4. display the #'s and accept the users answers from the keyboard on weather they perform addition subtraction mult, or division
5. calc the correct answer, compare the users answers to the answer calculated in the program
6. if user gets it correct display congratulations!
7. incorrect answers diplay incorrect!
8. after program operates display menu again, until users decides to end program by quitting.
Any form of help or snippets of code, or maybe what direction i should be heading in would be greatly apprecitated. Thanks in advance.
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
Here;s something you can work on. It may not be exactly what you need but its a basis at least. Also, why do you need to check if the second number of the division is zero, from the second you say it will accept values from 1-20?? Anyway, I put the check in the program as well if u need it for later on.. Hope it helps, byee
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <ctime> using namespace std; int DoMenu(); void addition(int random1, int random2); void subtraction(int random1, int random2); void multiplication(int random1, int random2); void division(int random1, int random2); int main() { int random1, random2; srand(time(0)); int choice; do { random1 = 1+(rand()%20); // from 1-20 random2 = 1+(rand()%20); // from 1-20 choice = DoMenu(); switch (choice) { case 0: cout << endl; break; case 1: addition(random1,random2); break; case 2: subtraction(random1,random2); break; case 3: multiplication(random1,random2); break; case 4: { if (random2 == 0) cout << "Error: Division by zero, cannot proceed\n"; else division(random1,random2); } break; default : cout << "Error in input\n\n"; break; } } while (choice != 0); return 0; } int DoMenu() { int MenuChoice; cout << "(1)Addition\n"; cout << "(2)Subtraction\n"; cout << "(3)Multiplication\n"; cout << "(4)Division\n"; cout << "(0)Quit\n"; cout << "-----------------\n"; cout << "Choice: "; cin >> MenuChoice; return MenuChoice; } void addition(int random1, int random2) { int answer; cout << "\n" << random1 << " + " << random2 << " = "; cin >> answer; if (answer == (random1+random2)) cout << "Congratulations\n\n"; else cout << "Incorrect\n\n"; } void subtraction(int random1, int random2) { int answer; cout << "\n" << random1 << " - " << random2 << " = "; cin >> answer; if (answer == (random1-random2)) cout << "Congratulations\n\n"; else cout << "Incorrect\n\n"; } void multiplication(int random1, int random2) { int answer; cout << "\n" << random1 << " * " << random2 << " = "; cin >> answer; if (answer == (random1*random2)) cout << "Congratulations\n\n"; else cout << "Incorrect\n\n"; } void division(int random1, int random2) { int answer; cout << "\n" << random1 << " / " << random2 << " = "; cin >> answer; if (answer == (random1/random2)) cout << "Congratulations\n\n"; else cout << "Incorrect\n\n"; }
•
•
Join Date: Nov 2006
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
>>I tried writing some code for this, but am having way to many issues
please post code, and use code tags as described in the links in my signature below.
#include<iostream> usingnamespace std; int Add(int x, int y); int Subtract(int x, int y); int Times (int x, int y); int Divide (int x, int y); int Remainder (int x, int y); int main() { int a,b,c,d,x=0; while (x!=77){ cout<<"1:Addition\n2:Subtraction\n3:Multiplication\n4:Division\n5:Quit"<<endl; cin>>x; a=rand()%19 + 1; b=rand()%19 + 1; switch(x) { case 1: cout<<a<<"+"<<b<<"=??"; d=Add(a,b); break; case 2: cout<<a<<"-"<<b<<"=??"; d=Subtract(a,b); break; case 3: cout<<a<<"*"<<b<<"=??"; d=Times(a,b); break; case 4: cout<<a<<"/"<<b<<"=??"; d=Divide(a,b); break; case 5: return 0; break; }//end switch(x) cin>>c; if (c==d) cout<<"Congratulations...You are Correct"; else cout<<"Incorrect...The correct answer is "<<d; if (x==4) cout<<"\nwith a remainder of "<<Remainder(a,b); cout<<endl<<endl; }//end while(x) } int Add(int x, int y) { int z; z=x+y; return z; } int Subtract (int x, int y) { int z; z=x-y; return z; } int Times (int x, int y) { int z; z=x*y; return z; } int Divide (int x, int y) { int z; z=x/y; return z; } int Remainder (int x, int y) { int z; z=x%y; return z; }
Last edited by ~s.o.s~; Dec 2nd, 2006 at 12:25 pm. Reason: A
I see in your code that you are not using
Try putting
HOpe it helped, bye.
srand( ) to seed or to initialize your random function and hence you are getting repetitive values.Try putting
srand( time(NULL) ) at the start of your code and then see. For more description see here.HOpe it helped, bye.
I don't accept change; I don't deserve to live.
•
•
Join Date: Nov 2006
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
I see in your code that you are not usingsrand( )to seed or to initialize your random function and hence you are getting repetitive values.
Try puttingsrand( time(NULL) )at the start of your code and then see. For more description see here.
HOpe it helped, bye.
Okay the thing is that while generating random numbers care has to be taken that the numbers so generated dont repeat in a pattern or frequently (though this would happen if the range is small).
To safeguard from this, normally all random generators make use of a base values (normally a very large number) which serves as a base or as a reference so that the numbers so generated using them dont repeat.
This said, care should be taken that the reference number should be as unique as possible and should not be ideally repeated.
The time( ) function returns the number of seconds that have passed since 00:00:00 GMT January 1, 1970. So when this value is passsed to the time function, it serves as a satisfactory reandom number generator reference or seed value as they call it.
More information here.
To safeguard from this, normally all random generators make use of a base values (normally a very large number) which serves as a base or as a reference so that the numbers so generated using them dont repeat.
This said, care should be taken that the reference number should be as unique as possible and should not be ideally repeated.
The time( ) function returns the number of seconds that have passed since 00:00:00 GMT January 1, 1970. So when this value is passsed to the time function, it serves as a satisfactory reandom number generator reference or seed value as they call it.
More information here.
I don't accept change; I don't deserve to live.
srand() takes a seed as an argument and in this case...the system's time is the seed which naturally keeps varying ....so you get a true random number simulation....there are so many other algos to generate random numbers....you can refer a good algorithm text....place srand(time(NULL)) anywhere before the rand() function
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
hey, so i also had a question about this as well but it's an extension to his basic math tutor problem. i used the code layout that may4life gave out which was fine and dandy but how do i get the program to where the user can practice math problems continuously until he/she decides to quit the program? i am teaching myself how to code but it's a slow process and the book and instructions aren't very clear to me and it's asking for this and have it in a do-while loop.it says the program should output the number of problems attempted, number of correct answers, and the score as a percentage as well. can anyone help me out? it's an online course as well so i'm sortof stuck on time a bit so any help here by sometime tonight would be very much appreciated. do i just make the do-while loop after typing in the if/else statements or after each if/else statement? sorry if this is the wrong place to be asking this and if it is then please let me know and let me know how to take care of my question so i can either move it or whatever i need to do. i'm just tryin to understand all this but i'm so much of a code noob that it's hard for me i guess. idk =/
Last edited by suikoden352; Mar 25th, 2009 at 10:35 pm. Reason: thread extention
![]() |
Similar Threads
- Giving code to posters rather than helping them (IT Professionals' Lounge)
Other Threads in the C++ Forum
- Previous Thread: Overloading operator>>
- Next Thread: C++ practice
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






