help plz!

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

Join Date: Jul 2005
Posts: 41
Reputation: jasondrey13 is an unknown quantity at this point 
Solved Threads: 0
jasondrey13's Avatar
jasondrey13 jasondrey13 is offline Offline
Light Poster

help plz!

 
0
  #1
Aug 13th, 2005
i tried to run this program but it comes up with the windows 6th grade algebra quiz has encuontered a problem and has to close message can
anyone help?
here is the code:

  1. #include <fstream>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <string>
  7. #include <conio.h>
  8.  
  9. using namespace std;
  10.  
  11. int report();
  12. int falseReport();
  13.  
  14. int nointros = 1;
  15. int noquestionswanted = 0;
  16. int grade = 0;
  17. int noguesses = 0;
  18. int noCorrect = 0;
  19. int nowrong = 0;
  20. int guess = 0;
  21. int X = 0;
  22. int a = 0;
  23. int b = 0;
  24. int X2 = 0;
  25. int a2 = 0;
  26. int b2 = 0;
  27. int problem = 0;
  28. double area = 0;
  29. int R = 0;
  30. int lob = 0;
  31. int heighth = 0;
  32. int R2 = 0;
  33. int area2 = 0;
  34. int nothing = 0;
  35.  
  36. int main()
  37. {
  38.  
  39.  
  40. if(noguesses == noquestionswanted )
  41. {
  42. report();
  43. }
  44.  
  45. if(nointros == 1)
  46. {
  47. cout<<"hi this is the pre-algabra quiz"<<endl;
  48. cout<<"if you are taking this you will need a pencil and paper";
  49. cout<<"once you have done that press any number and enter to continue";
  50. cin>>nothing;
  51. cout<<"how many questions would you like"<<endl;
  52. cout<<"1. 10"<<endl;
  53. cout<<"2. 15"<<endl;
  54. cout<<"3. 20"<<endl;
  55. cin>>noquestionswanted;
  56. nointros++;
  57. if(noquestionswanted == 1)
  58.  
  59. {
  60.  
  61.  
  62. noquestionswanted = 10;
  63.  
  64.  
  65. }
  66. else if(noquestionswanted == 2)
  67.  
  68. {
  69.  
  70.  
  71. noquestionswanted = 15;
  72.  
  73.  
  74. }
  75. else if(noquestionswanted == 3)
  76.  
  77. {
  78.  
  79.  
  80. noquestionswanted = 20;
  81.  
  82.  
  83. }
  84. else if(noquestionswanted == 999)
  85.  
  86. {
  87.  
  88.  
  89. falseReport();
  90.  
  91. return 0;
  92. }
  93. else
  94. {
  95.  
  96. cout<<"I'm sorry that is not a choice please type 1, 2, or 3 next time"<<endl;
  97.  
  98. main();
  99.  
  100. }
  101. cout<<"press any number and enter to begin";
  102.  
  103. }
  104.  
  105. else
  106. {
  107.  
  108. cout<<"press any number and enter to continue";
  109.  
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117. cin>>nothing;
  118.  
  119. srand((unsigned)time(NULL));
  120. problem = 1 + rand() % 5;
  121.  
  122.  
  123.  
  124. if(problem == 1)
  125. {
  126.  
  127. srand((unsigned)time(NULL));
  128. b = 1 + rand() % 100;
  129.  
  130. srand((unsigned)time(NULL));
  131. a = 1 + rand() % 100;
  132.  
  133.  
  134. X = b - a;
  135.  
  136. cout<<"solve this equasion"<<endl;
  137. cout<<"a+x=b if a="<<a<<endl;
  138. cout<<"and b="<<b<<endl;
  139.  
  140. cin>>guess;
  141.  
  142. if(guess == X)
  143. {
  144.  
  145. cout<<"correct!";
  146.  
  147. noCorrect++;
  148.  
  149. noguesses++;
  150. }
  151. else
  152. {
  153. cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl;
  154.  
  155. cout<<X<<endl;
  156.  
  157. nowrong++;
  158. noguesses++;
  159. }
  160.  
  161. main();
  162.  
  163. return 0;
  164. }
  165.  
  166. else if(problem == 2)
  167. {
  168.  
  169. srand((unsigned)time(NULL));
  170. b2 = 1 + rand() % 100;
  171.  
  172. srand((unsigned)time(NULL));
  173. a2 = 1 + rand() % 100;
  174.  
  175.  
  176. X2 = a2 - b2;
  177.  
  178.  
  179. if(guess == X)
  180. {
  181.  
  182. cout<<"correct!"<<endl;
  183.  
  184. noCorrect++;
  185.  
  186. noguesses++;
  187. }
  188. else
  189. {
  190. cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl;
  191.  
  192. cout<<X2<<endl;
  193.  
  194. nowrong++;
  195. noguesses++;
  196. }
  197.  
  198.  
  199.  
  200.  
  201.  
  202. main();
  203.  
  204.  
  205. return 0;
  206.  
  207. }
  208.  
  209.  
  210.  
  211. else if(problem == 3)
  212. {
  213.  
  214.  
  215.  
  216. srand((unsigned)time(NULL));
  217. R = 1 + rand() % 100;
  218.  
  219.  
  220.  
  221. cin>>R;
  222. R2 = R *= R;
  223. area = 3.1415926 * R2;
  224.  
  225.  
  226.  
  227. if(guess == area)
  228. {
  229.  
  230. cout<<"correct!"<<endl;
  231.  
  232. noCorrect++;
  233.  
  234. noguesses++;
  235. }
  236. else
  237. {
  238. cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl;
  239.  
  240. cout<<X2<<endl;
  241.  
  242. nowrong++;
  243. noguesses++;
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250. main();
  251.  
  252.  
  253. return 0;
  254.  
  255. }
  256.  
  257. else if(problem == 4)
  258. {
  259.  
  260.  
  261.  
  262.  
  263. srand((unsigned)time(NULL));
  264. heighth = 1 + rand() % 100;
  265.  
  266. srand((unsigned)time(NULL));
  267. lob = 1 + rand() % 100;
  268.  
  269.  
  270.  
  271. area2 = heighth*lob/2;
  272.  
  273. cout<<"what is the area of a triangle with a height"<<endl;
  274. cout<<"of "<<heighth<<"and a base length of "<<lob<<"?"<<endl;
  275.  
  276. cin>>guess;
  277.  
  278. if(guess == area2)
  279. {
  280.  
  281. cout<<"correct!"<<endl;
  282.  
  283. noCorrect++;
  284.  
  285. noguesses++;
  286. }
  287. else
  288. {
  289. cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl;
  290.  
  291. cout<<X<<endl;
  292.  
  293. nowrong++;
  294. noguesses++;
  295. }
  296.  
  297. main();
  298.  
  299. return 0;
  300. }
  301.  
  302.  
  303. else if(problem == 5)
  304. {
  305.  
  306.  
  307.  
  308.  
  309. srand((unsigned)time(NULL));
  310. heighth = 1 + rand() % 100;
  311.  
  312. srand((unsigned)time(NULL));
  313. lob = 1 + rand() % 100;
  314.  
  315.  
  316.  
  317. area2 = heighth*lob/2;
  318.  
  319.  
  320. cout<<"what is the area of a square or rectangle with a height"<<endl;
  321. cout<<"of "<<heighth<<"and a base length of "<<lob<<"?"<<endl;
  322.  
  323. cin>>guess;
  324.  
  325. if(guess == area)
  326. {
  327.  
  328. cout<<"correct!"<<endl;
  329.  
  330. noCorrect++;
  331.  
  332. noguesses++;
  333. }
  334. else
  335. {
  336. cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl;
  337.  
  338. cout<<X<<endl;
  339.  
  340. nowrong++;
  341. noguesses++;
  342. }
  343.  
  344. main();
  345.  
  346. return 0;
  347. }
  348.  
  349.  
  350.  
  351. else
  352. {
  353. cout<<"please choose 1, 2, 3, 4, or 5"<<endl;
  354.  
  355. main();
  356.  
  357.  
  358. return 0;
  359. }
  360.  
  361.  
  362.  
  363. return 0;
  364. }
  365.  
  366.  
  367.  
  368.  
  369. report()
  370. {
  371. grade = noCorrect / noguesses * 100;
  372.  
  373. cout<<"your final report for the "<<noguesses<<" qustions you answered are as followed"<<endl;
  374. cout<<"you got "<<noCorrect<<"correct and "<<nowrong<<" wrong "<<endl;
  375. cout<<"your grade is a "<<grade<<" percent"<<endl;
  376. cout<<"the program is over";
  377.  
  378. return 0;
  379. }
  380. falseReport()
  381. {
  382.  
  383. cout<<"your final report for the 20 qustions you answered are as followed"<<endl;
  384. cout<<"you got 20 correct and 0 wrong"<<endl;
  385. cout<<"the program is over";
  386.  
  387.  
  388. return 0;
  389. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help plz!

 
0
  #2
Aug 13th, 2005
[Pointless bumps deleted.]

It shouldn't compile because C++ does not allow recursive calls to main.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: jasondrey13 is an unknown quantity at this point 
Solved Threads: 0
jasondrey13's Avatar
jasondrey13 jasondrey13 is offline Offline
Light Poster

Re: help plz!

 
0
  #3
Aug 13th, 2005
what doyou mean?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help plz!

 
0
  #4
Aug 13th, 2005
I mean it shouldn't compile.
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
testpp.cpp:
Error E2120 testpp.cpp 94: Cannot call 'main' from within the program in function main()
Error E2120 testpp.cpp 157: Cannot call 'main' from within the program in function main()
Error E2120 testpp.cpp 198: Cannot call 'main' from within the program in function main()
Error E2120 testpp.cpp 246: Cannot call 'main' from within the program in function main()
Error E2120 testpp.cpp 293: Cannot call 'main' from within the program in function main()
Error E2120 testpp.cpp 340: Cannot call 'main' from within the program in function main()
Error E2120 testpp.cpp 351: Cannot call 'main' from within the program in function main()
Warning W8066 testpp.cpp 359: Unreachable code in function main()
*** 7 errors in Compile ***
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: jasondrey13 is an unknown quantity at this point 
Solved Threads: 0
jasondrey13's Avatar
jasondrey13 jasondrey13 is offline Offline
Light Poster

Re: help plz!

 
0
  #5
Aug 13th, 2005
it says that there arent any errors onvisual studio 2003 .net
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 62
Reputation: freemind is an unknown quantity at this point 
Solved Threads: 1
freemind's Avatar
freemind freemind is offline Offline
Junior Poster in Training

Re: help plz!

 
0
  #6
Aug 13th, 2005
Then consider using another compiler. If you want to start over when something in the user's choice goes wrong you can either provide an ethernal loop around the code that should be performed over and over again until the user gives a correct input or use labels. I recommend you the first option. If you choose the second one you would probably want to know something about "goto"...
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help plz!

 
0
  #7
Aug 13th, 2005
I saw somewhere that C++98 states,
3.6.1, par 3
[...]
The function main shall not be used (3.2) within a program.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: help plz!

 
0
  #8
Aug 13th, 2005
>it says that there arent any errors onvisual studio 2003 .net
That's nice, and your point is? I get the same lack of error, but that doesn't make it any less wrong. The only difference between you and me is that I know it's wrong and you're trying to give the "it works for me" argument that so many ignorant people love.

>you would probably want to know something about "goto"...
Yes, and that something would be that it should be used sparingly. I just felt the need to chime in before somebody says "NEVER use goto, it's teh EVIL!!!!111"
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: jasondrey13 is an unknown quantity at this point 
Solved Threads: 0
jasondrey13's Avatar
jasondrey13 jasondrey13 is offline Offline
Light Poster

Re: help plz!

 
0
  #9
Aug 15th, 2005
ok you keep workin on that...

whatever ok does anyone know where to get a new free (hopefully i dont exactly have 300$ siting on my desk ('.')) good compiler?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help plz!

 
0
  #10
Aug 15th, 2005
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
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