either include stdlib.h and use system("PAUSE") at the end of the program, or include stdio and use getchar()
Parse Error?
oh, and also,
cin >> somefakevariable works pretty well, for example
char somefakevariable;
cin >> somefakevariable;
:D
cin >> somefakevariable works pretty well, for example
char somefakevariable;
cin >> somefakevariable;
:D
Ok, now I have a new error.
When I try this...
after a question in my trivia game, it compiles with zero errors but after I answer the question in the dos program, it always says wrong no matter what I typed in. Is it a problem with my if/else if statement?
Oh, FYI, "x" is the results thing and "pick1" is the choice they enter.
When I try this...
if(pick1==2) { cout<<"You''re right!\n"; x=x+1; b(); }else if(pick1!=2) { cout<<"Wrong. The correct answer was 2.\n"; b(); }}
after a question in my trivia game, it compiles with zero errors but after I answer the question in the dos program, it always says wrong no matter what I typed in. Is it a problem with my if/else if statement?
Oh, FYI, "x" is the results thing and "pick1" is the choice they enter.
Again, we need a little more information to help you, such as the type of pick1 (I''ll just assume it''s an int) and the scope of the if-elseif statement black. However, here''s a little tip: since "2" is the only correct answer, do:
The other thing is make sure your pick1 is an integer (int); if it''s a char then it wont behave the way you expect.
if(pick1 == 2){ cout << "You''re right!\n"; // ++x, x++, x+= 1 and x = x+1 are similar. // Since you don''t care whether it happens before // or after this statment, use ++x; ++x; b();}else{ cout << "Sorry, the answer is 2.\n"; b();}
The other thing is make sure your pick1 is an integer (int); if it''s a char then it wont behave the way you expect.
I tried that and it still didn''t work. Here is the whole thing.
#include <stdio.h>#include <iostream.h>void a();void b();void c();void start();void results();int pick, x;void a(){int pick1;cout<<"How many bones are in the human body?\n";cout<<"1. 100\n";cout<<"2. 206\n";cout<<"3. 266\n";cout<<"4. Over 1000\n";cin>>pick;pick=pick1;if(pick1==2) { cout<<"You''re right!\n"; ++x; b(); }else { cout<<"Wrong. The correct answer was 2.\n"; b(); }}void b(){int pick2;cout<<"What is the name of our currenet president?\n";cout<<"1. Ronald Reagan\n";cout<<"2. John Kennedy\n";cout<<"3. Bill Clinton\n";cout<<"4. George Bush\n";cin>>pick;pick=pick2;if(pick2==4) { cout<<"You''re right!\n"; ++x; c(); }else { cout<<"Wrong. The correct answer was 4.\n"; c(); }}void c(){int pick3;cout<<"What is 12x12?\n";cout<<"1. 100\n";cout<<"2. 122\n";cout<<"3. 144\n";cout<<"4. 1212\n";cin>>pick;pick=pick3;if(pick3==3) { cout<<"You''re right!\n"; ++x; results(); }else { cout<<"Wrong. The correct answer was 3.\n"; results(); }}void results(){cout<<"Your score was "<<x<<".\n";start();}void start(){cout<<"Welcome. Here is your first question.\n";a();}int main(int argc, char *argv[]){cout<<"Welcome to the trivia game.\n";cout<<"To play, type in a number 1-4 in accordance with the question.\n";start();}
I really am stupid.
All I had to do was take out int pick at the top and pick=pick 3 etc. and it worked fine! Thank you guys for all your help.
All I had to do was take out int pick at the top and pick=pick 3 etc. and it worked fine! Thank you guys for all your help.
Ok, here is what you have:
Look at these two lines in particular:
it should be:
otherwise you overwrite the value you read in with the uninitialized value that was in pick1 when the routine was put on the stack.
Remeber your assignment ordering. The variable to left of the operator receives the value from the variable to the right of the operator.
RandomTask
int pick1;cout<<"How many bones are in the human body?\n";cout<<"1. 100\n";cout<<"2. 206\n";cout<<"3. 266\n";cout<<"4. Over 1000\n";cin>>pick;pick=pick1;if(pick1==2){ cout<<"You''re right!\n"; ++x; b();}else{ cout<<"Wrong. The correct answer was 2.\n"; b();}
Look at these two lines in particular:
cin>>pick;pick=pick1;
it should be:
pick1=pick;
otherwise you overwrite the value you read in with the uninitialized value that was in pick1 when the routine was put on the stack.
Remeber your assignment ordering. The variable to left of the operator receives the value from the variable to the right of the operator.
RandomTask
Ok, I promise, this is the last parse error. I added a lot to the program and I can get it down to one error:
Parse error at end of input
I didn''t change int main() at all so why is it saying parse error at end of input?
I would post the new thing up there but it is really long(like 175 lines) so if you can help, thanks.
My e-mail is "Rick__33@hotmail.com" if you want to see it.
Parse error at end of input
I didn''t change int main() at all so why is it saying parse error at end of input?
I would post the new thing up there but it is really long(like 175 lines) so if you can help, thanks.
My e-mail is "Rick__33@hotmail.com" if you want to see it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement