| | |
help plz!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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:
anyone help?
here is the code:
C++ Syntax (Toggle Plain Text)
#include <fstream> #include <cstdlib> #include <iostream> #include <stdlib.h> #include <time.h> #include <string> #include <conio.h> using namespace std; int report(); int falseReport(); int nointros = 1; int noquestionswanted = 0; int grade = 0; int noguesses = 0; int noCorrect = 0; int nowrong = 0; int guess = 0; int X = 0; int a = 0; int b = 0; int X2 = 0; int a2 = 0; int b2 = 0; int problem = 0; double area = 0; int R = 0; int lob = 0; int heighth = 0; int R2 = 0; int area2 = 0; int nothing = 0; int main() { if(noguesses == noquestionswanted ) { report(); } if(nointros == 1) { cout<<"hi this is the pre-algabra quiz"<<endl; cout<<"if you are taking this you will need a pencil and paper"; cout<<"once you have done that press any number and enter to continue"; cin>>nothing; cout<<"how many questions would you like"<<endl; cout<<"1. 10"<<endl; cout<<"2. 15"<<endl; cout<<"3. 20"<<endl; cin>>noquestionswanted; nointros++; if(noquestionswanted == 1) { noquestionswanted = 10; } else if(noquestionswanted == 2) { noquestionswanted = 15; } else if(noquestionswanted == 3) { noquestionswanted = 20; } else if(noquestionswanted == 999) { falseReport(); return 0; } else { cout<<"I'm sorry that is not a choice please type 1, 2, or 3 next time"<<endl; main(); } cout<<"press any number and enter to begin"; } else { cout<<"press any number and enter to continue"; } cin>>nothing; srand((unsigned)time(NULL)); problem = 1 + rand() % 5; if(problem == 1) { srand((unsigned)time(NULL)); b = 1 + rand() % 100; srand((unsigned)time(NULL)); a = 1 + rand() % 100; X = b - a; cout<<"solve this equasion"<<endl; cout<<"a+x=b if a="<<a<<endl; cout<<"and b="<<b<<endl; cin>>guess; if(guess == X) { cout<<"correct!"; noCorrect++; noguesses++; } else { cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl; cout<<X<<endl; nowrong++; noguesses++; } main(); return 0; } else if(problem == 2) { srand((unsigned)time(NULL)); b2 = 1 + rand() % 100; srand((unsigned)time(NULL)); a2 = 1 + rand() % 100; X2 = a2 - b2; if(guess == X) { cout<<"correct!"<<endl; noCorrect++; noguesses++; } else { cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl; cout<<X2<<endl; nowrong++; noguesses++; } main(); return 0; } else if(problem == 3) { srand((unsigned)time(NULL)); R = 1 + rand() % 100; cin>>R; R2 = R *= R; area = 3.1415926 * R2; if(guess == area) { cout<<"correct!"<<endl; noCorrect++; noguesses++; } else { cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl; cout<<X2<<endl; nowrong++; noguesses++; } main(); return 0; } else if(problem == 4) { srand((unsigned)time(NULL)); heighth = 1 + rand() % 100; srand((unsigned)time(NULL)); lob = 1 + rand() % 100; area2 = heighth*lob/2; cout<<"what is the area of a triangle with a height"<<endl; cout<<"of "<<heighth<<"and a base length of "<<lob<<"?"<<endl; cin>>guess; if(guess == area2) { cout<<"correct!"<<endl; noCorrect++; noguesses++; } else { cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl; cout<<X<<endl; nowrong++; noguesses++; } main(); return 0; } else if(problem == 5) { srand((unsigned)time(NULL)); heighth = 1 + rand() % 100; srand((unsigned)time(NULL)); lob = 1 + rand() % 100; area2 = heighth*lob/2; cout<<"what is the area of a square or rectangle with a height"<<endl; cout<<"of "<<heighth<<"and a base length of "<<lob<<"?"<<endl; cin>>guess; if(guess == area) { cout<<"correct!"<<endl; noCorrect++; noguesses++; } else { cout<<"I'm sorry but you got it wrong the corect answer is:"<<endl; cout<<X<<endl; nowrong++; noguesses++; } main(); return 0; } else { cout<<"please choose 1, 2, 3, 4, or 5"<<endl; main(); return 0; } return 0; } report() { grade = noCorrect / noguesses * 100; cout<<"your final report for the "<<noguesses<<" qustions you answered are as followed"<<endl; cout<<"you got "<<noCorrect<<"correct and "<<nowrong<<" wrong "<<endl; cout<<"your grade is a "<<grade<<" percent"<<endl; cout<<"the program is over"; return 0; } falseReport() { cout<<"your final report for the 20 qustions you answered are as followed"<<endl; cout<<"you got 20 correct and 0 wrong"<<endl; cout<<"the program is over"; return 0; }
[Pointless bumps deleted.]
It shouldn't compile because C++ does not allow recursive calls to main.
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
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
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"...
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"... 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
>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"
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.
![]() |
Similar Threads
- can someone plz help me with this? (Visual Basic 4 / 5 / 6)
- I NEED SUPPORT **"IMPORTANT"** PLZ HELP (Windows NT / 2000 / XP)
- Windows media player (Windows NT / 2000 / XP)
- Bridge.dll...Make it go away, Plz (Viruses, Spyware and other Nasties)
- can sum1 look @ dis plz (Viruses, Spyware and other Nasties)
- Hijackthis log file - plz help (Viruses, Spyware and other Nasties)
- IE not working...PLZ help :cry: (Web Browsers)
- PLZ help it's urgent! (Web Browsers)
- plz help ppl...... (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Number input problem.
- Next Thread: How do you build the dot in calculator.
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






