+ 1

What's causing the error?

its not yet completed, please review..... https://code.sololearn.com/cG4Q6qKPqtO9/?ref=app

24th Sep 2018, 6:38 AM
Sakaar Sen
Sakaar Sen - avatar
2 Respuestas
+ 3
Hi! You can read the comments: #include <iostream> using namespace std; int main() { cout << "Welcome to the quiz, Would you like you know the rules?" << endl; Options: cout << "Enter y for yes or n for no" << endl ; string rulesopt; cin>>rulesopt; if(rulesopt == "y"){ cout << "You would be asked 5 questions and for every right answer, you would get 1 point.SimPle!" << endl; } if (rulesopt == "n"){ cout << "I assume you already know the rules, so lets head over to the game now ....!"<<endl; } if(rulesopt != "n" && rulesopt!= "y") { cout <<endl<<endl<< "Please choose a valid option."; goto Options ; } Quiz: int a,b; //You need to declare a and b here //if this is here you can use it in all place in your code. cout << endl << endl << "Question 1" << endl << "What is 2+2?" << endl; string ans1; cin>>ans1; //Here needs ; if(ans1 == "4"){ cout << "Right answer...
24th Sep 2018, 6:54 AM
Nimrod A. Holguín L.
Nimrod A. Holguín L. - avatar
+ 3
cout << "Right answer...That was an easy one!"<<endl; a=1; } else{ cout<< "BEEP! Looks like that was a wrong answer,Better luck next time.... "<<endl; a = 0; } cout << endl << endl << "Question 2"<< endl << "Which one out of these is a leap year: 1600 or 1800"<<endl; string ans2 ; cin>>ans2; if(ans2 == "1600"){ cout << "Congo! RigHt AnSweR"; b = 1; } if(ans2 != "1600"){ cout << "Looks like you chose the wrong ans..."<<endl; b = 0; } //Now you avoid the error here //Because a and b are not inside of the conditional if; int sum = a+b; cout << sum; return 0; } /* Remember, this compiler needs all inputs when the code is starting. */
24th Sep 2018, 6:55 AM
Nimrod A. Holguín L.
Nimrod A. Holguín L. - avatar