Math Tutoring Program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 3
Reputation: myboo11009 is an unknown quantity at this point 
Solved Threads: 0
myboo11009 myboo11009 is offline Offline
Newbie Poster

Math Tutoring Program

 
0
  #1
Nov 27th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,519
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Math Tutoring Program

 
0
  #2
Nov 27th, 2006
>>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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

Re: Math Tutoring Program

 
0
  #3
Nov 28th, 2006
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
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int DoMenu();
  7. void addition(int random1, int random2);
  8. void subtraction(int random1, int random2);
  9. void multiplication(int random1, int random2);
  10. void division(int random1, int random2);
  11.  
  12. int main()
  13. {
  14. int random1, random2;
  15. srand(time(0));
  16.  
  17. int choice;
  18.  
  19. do
  20. {
  21. random1 = 1+(rand()%20); // from 1-20
  22. random2 = 1+(rand()%20); // from 1-20
  23.  
  24. choice = DoMenu();
  25.  
  26. switch (choice)
  27. {
  28. case 0: cout << endl; break;
  29. case 1: addition(random1,random2); break;
  30. case 2: subtraction(random1,random2); break;
  31. case 3: multiplication(random1,random2); break;
  32. case 4:
  33. {
  34. if (random2 == 0)
  35. cout << "Error: Division by zero, cannot proceed\n";
  36. else
  37. division(random1,random2);
  38. } break;
  39. default : cout << "Error in input\n\n"; break;
  40. }
  41.  
  42. } while (choice != 0);
  43.  
  44. return 0;
  45. }
  46.  
  47. int DoMenu()
  48. {
  49. int MenuChoice;
  50. cout << "(1)Addition\n";
  51. cout << "(2)Subtraction\n";
  52. cout << "(3)Multiplication\n";
  53. cout << "(4)Division\n";
  54. cout << "(0)Quit\n";
  55. cout << "-----------------\n";
  56. cout << "Choice: ";
  57. cin >> MenuChoice;
  58. return MenuChoice;
  59. }
  60.  
  61. void addition(int random1, int random2)
  62. {
  63. int answer;
  64.  
  65. cout << "\n" << random1 << " + " << random2 << " = ";
  66. cin >> answer;
  67.  
  68. if (answer == (random1+random2))
  69. cout << "Congratulations\n\n";
  70. else
  71. cout << "Incorrect\n\n";
  72. }
  73.  
  74. void subtraction(int random1, int random2)
  75. {
  76. int answer;
  77.  
  78. cout << "\n" << random1 << " - " << random2 << " = ";
  79. cin >> answer;
  80.  
  81. if (answer == (random1-random2))
  82. cout << "Congratulations\n\n";
  83. else
  84. cout << "Incorrect\n\n";
  85. }
  86.  
  87. void multiplication(int random1, int random2)
  88. {
  89. int answer;
  90.  
  91. cout << "\n" << random1 << " * " << random2 << " = ";
  92. cin >> answer;
  93.  
  94. if (answer == (random1*random2))
  95. cout << "Congratulations\n\n";
  96. else
  97. cout << "Incorrect\n\n";
  98. }
  99.  
  100. void division(int random1, int random2)
  101. {
  102. int answer;
  103.  
  104. cout << "\n" << random1 << " / " << random2 << " = ";
  105. cin >> answer;
  106.  
  107. if (answer == (random1/random2))
  108. cout << "Congratulations\n\n";
  109. else
  110. cout << "Incorrect\n\n";
  111. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 3
Reputation: myboo11009 is an unknown quantity at this point 
Solved Threads: 0
myboo11009 myboo11009 is offline Offline
Newbie Poster

Re: Math Tutoring Program

 
0
  #4
Dec 2nd, 2006
Originally Posted by Ancient Dragon View Post
>>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.
Here is the code: My problem is the random numbers...they always come up the same as 4 and 19. Can someone help me with the random numbers. They have to be between 1-20. Thanks
#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
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,629
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Math Tutoring Program

 
0
  #5
Dec 2nd, 2006
I see in your code that you are not using 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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 3
Reputation: myboo11009 is an unknown quantity at this point 
Solved Threads: 0
myboo11009 myboo11009 is offline Offline
Newbie Poster

Re: Math Tutoring Program

 
0
  #6
Dec 2nd, 2006
Originally Posted by ~s.o.s~ View Post
I see in your code that you are not using 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 checked out the help from your page on where to put this snippet of code, But I never learned that function yet and still am having difficulty with trying to understand this srad. Can you maybe walk me through it a little better. What do I substitute for time? its a number generator program.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,629
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Math Tutoring Program

 
0
  #7
Dec 2nd, 2006
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 17
Reputation: sugantha is an unknown quantity at this point 
Solved Threads: 0
sugantha's Avatar
sugantha sugantha is offline Offline
Newbie Poster

Re: Math Tutoring Program

 
0
  #8
Dec 2nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: suikoden352 is an unknown quantity at this point 
Solved Threads: 0
suikoden352 suikoden352 is offline Offline
Newbie Poster

Re: Math Tutoring Program

 
0
  #9
Mar 25th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 109
Reputation: SeeTheLite is an unknown quantity at this point 
Solved Threads: 12
SeeTheLite SeeTheLite is offline Offline
Junior Poster

Re: Math Tutoring Program

 
0
  #10
Mar 25th, 2009
Holy Necro Bump Batman, make a new thread and I'll see what I can do for you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC