We help IT Professionals succeed at work.
Get Started

Why wont my multiple choice code work (entire code pasted)?

cscotty
cscotty asked
on
231 Views
Last Modified: 2010-04-01
Hey all.  I've been trying this code all morning.  I am trying to make a multiple choice review assuiming that the users will indicate the number when answering.  The only thing is that my first answer works but the other 19 does not.  I've used the same format.  Whats the problem? Please help.

here is my code:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])

{
    //Below is the format and notes that will be used for all the questions.
    //Only one occurence of these notes will be made.
   
    //Define vairiables
    int a1, b1;
        b1 = 4;
   
    //Multiple choice question name q1:
    q1:
    cout<<"What are the colors of the United States Flag?\n\n";
   
    //Possible Answers...User should choose the number, not the name (i.e. 1, 2, 3, or 4)
    cout<<"1.  Black, Gold, Green\n";
    cout<<"2.  Red, White\n";
    cout<<"3.  Blue, Black, Red, White\n";
    cout<<"4.  Red, White, Blue\n\n";
   
    //Users Answer
    cin>>a1;
    cout<<"\n\n";

    //Ignore the "ENTER" key as part of the answer
    cin.ignore();
   
    //IF the answer is correct, proceed to the next question.  If not try again.
    if(b1==a1){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q2;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q1;
    }

    //Question #2
    int a2, b2;
    b2 = 1;
    q2:
    cout<<"What do the stars of the flag mean?\n\n";
   
    cout<<"1.  One for each State\n";
    cout<<"2.  One for each President\n";
    cout<<"3.  One for each Senator\n";
    cout<<"4.  The amount of wars the USA won\n\n";
   
    cin>>a2;
    cout<<"\n\n";
    cin.ignore();
   
    if(b2==a2){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q3;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q2;
    }
   
    //Question #3
    int a3, b3;
    b3 = 3;
    q3:
    cout<<"How many stars are there on the American Flag?\n\n";
   
    cout<<"1.  45\n";
    cout<<"2.  46\n";
    cout<<"3.  50\n";
    cout<<"4.  51\n\n";
   
    cin>>a3;
    cout<<"\n\n";
    cin.ignore();
   
    if(b3==a3){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q4;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q3;
    }
   
    //Question #4
    int a4, b4;
    b4 = 1;
    q4:
    cout<<"What colors are the stars on the American flag?\n\n";
   
    cout<<"1.  White\n";
    cout<<"2.  Red\n";
    cout<<"3.  Blue\n";
    cout<<"4.  Gold\n\n";
   
    cin>>a4;
    cout<<"\n\n";
    cin.ignore();
   
    if(b4==a4){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q5;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q4;
    }
   
    //Question #5
    int a5, b5;
    b5 = 3;
    q5:
    cout<<"How many stripes are there on the flag?\n\n";
   
    cout<<"1.  15\n";
    cout<<"2.  50\n";
    cout<<"3.  13\n";
    cout<<"4.  20\n\n";
   
    cin>>a5;
    cout<<"\n\n";
    cin.ignore();
   
    if(b5==a5){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q6;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q5;
    }
   
    //Question #6
    int a6, b6;
    b6 = 2;
    q6:
    cout<<"What do the stripes on the flag represent?\n\n";
   
    cout<<"1.  The first 26 States\n";
    cout<<"2.  The first 13 States\n";
    cout<<"3.  The first 13 Presidents\n";
    cout<<"4.  The first 13 Highways\n\n";
   
    cin>>a6;
    cout<<"\n\n";
    cin.ignore();
   
    if(b6==a6){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q7;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q6;
    }
   
    //Question #7
    int a7, b7;
    b7 = 1;
    q7:
    cout<<"What colors are the stripes on the flag??\n\n";
   
    cout<<"1.  Red, White\n";
    cout<<"2.  Red, White, Blue\n";
    cout<<"3.  Red, Blue\n";
    cout<<"4.  White\n\n";
   
    cin>>a7;
    cout<<"\n\n";
    cin.ignore();
   
    if(b7==a7){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q8;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q7;
    }
   
    //Question #8
    int a8, b8;
    b8 = 4;
    q8:
    cout<<"How many states are in the USA?\n\n";
   
    cout<<"1.  40\n";
    cout<<"2.  45\n";
    cout<<"3.  51\n";
    cout<<"4.  50\n\n";
   
    cin>>a8;
    cout<<"\n\n";
    cin.ignore();
   
    if(b8==a8){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q9;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q8;
    }
   
    //Question #9
    int a9, b9;
    b9 = 2;
    q9:
    cout<<"What is celebrated on July 4th?\n\n";
   
    cout<<"1.  Holloween\n";
    cout<<"2.  Independence Day\n";
    cout<<"3.  Memorial Day\n";
    cout<<"4.  Presidents Day\n\n";
   
    cin>>a9;
    cout<<"\n\n";
    cin.ignore();
   
    if(b9==a9){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q10;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q9;
    }
   
    //Question #10
    int a10, b10;
    b10 = 3;
    q10:
    cout<<"Independence Day celebrates independence from whom??\n\n";
   
    cout<<"1.  Japan\n";
    cout<<"2.  China\n";
    cout<<"3.  England\n";
    cout<<"4.  Africa\n\n";
   
    cin>>a10;
    cout<<"\n\n";
    cin.ignore();
   
    if(b10==a10){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q11;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q10;
    }
   
    //Question #11
    int a11, b11;
    b11 = 1;
    q11:
    cout<<"What country did the US fight during the Revolutionary War?\n\n";
   
    cout<<"1.  England\n";
    cout<<"2.  Japan\n";
    cout<<"3.  China\n";
    cout<<"4.  Germany\n\n";
   
    cin>>a11;
    cout<<"\n\n";
    cin.ignore();
   
    if(b11==a11){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q12;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q11;
    }
   
    //Question #12
    int a12, b12;
    b12 = 4;
    q12:
    cout<<"Who was the first president of the United States?\n\n";
   
    cout<<"1.  George Jefferson\n";
    cout<<"2.  George W. Bush\n";
    cout<<"3.  Curious George\n";
    cout<<"4.  George Washington\n\n";
   
    cin>>a12;
    cout<<"\n\n";
    cin.ignore();
   
    if(b12==a12){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q13;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q12;
    }
   
    //Question #13
    int a13, b13;
    b13 = 2;
    q13:
    cout<<"Who is the President of the United States tdoay?\n\n";
   
    cout<<"1.  George Washington\n";
    cout<<"2.  George W. Bush\n";
    cout<<"3.  Bill Clinton\n";
    cout<<"4.  Abraham Lincoln\n\n";
   
    cin>>a13;
    cout<<"\n\n";
    cin.ignore();
   
    if(b13==a13){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q14;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q13;
    }
   
    //Question #14
    int a14, b14;
    b14 = 3;
    q14:
    cout<<"Richard Chaney is the...\n\n";
   
    cout<<"1.  Mayor of New Jersey\n";
    cout<<"2.  Governor of New Jersey\n";
    cout<<"3.  Vice President\n";
    cout<<"4.  Senator of New Jersey\n\n";
   
    cin>>b14;
    cout<<"\n\n";
    cin.ignore();
   
    if(b14==a14){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q15;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q14;
    }
   
    //Question #15
    int a15, b15;
    b15 = 3;
    q15:
    cout<<"Who elects the President of the USA?\n\n";
   
    cout<<"1.  The Senators\n";
    cout<<"2.  We the people\n";
    cout<<"3.  The Electoral College\n";
    cout<<"4.  The Electoral University\n\n";
   
    cin>>a15;
    cout<<"\n\n";
    cin.ignore();
   
    if(b5==a15){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q16;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q15;
    }
   
    //Question #16
    int a16, b16;
    b16 = 2;
    q16:
    cout<<"If the President dies, who becomes president?\n\n";
   
    cout<<"1.  The runner up\n";
    cout<<"2.  The Vice President\n";
    cout<<"3.  No one until the end of the 4-year term\n";
    cout<<"4.  The First lady\n\n";
   
    cin>>a16;
    cout<<"\n\n";
    cin.ignore();
   
    if(b16==a16){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q17;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q16;
    }
   
    //Question #17
    int a17, b17;
    b17 = 1;
    q17:
    cout<<"What is the constitution?\n\n";
   
    cout<<"1.  The supreme law of the land\n";
    cout<<"2.  A religious freedom act\n";
    cout<<"3.  The place where Congress meets\n";
    cout<<"4.  Rules forced on by Germany\n\n";
   
    cin>>a17;
    cout<<"\n\n";
    cin.ignore();
   
    if(b17==a17){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q18;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q17;
    }
   
    //Question #18
    int a18, b18;
    b18 = 1;
    q18:
    cout<<"What are changes to the Constitution called??\n\n";
   
    cout<<"1.  Amendments\n";
    cout<<"2.  Protocols\n";
    cout<<"3.  Investigator's Brochures\n";
    cout<<"4.  Final Report\n\n";
   
    cin>>a18;
    cout<<"\n\n";
    cin.ignore();
   
    if(b18==a18){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q19;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q18;
    }
   
    //Question #19
    int a19, b19;
    b19 = 1;
    q19:
    cout<<"How many changes or amendments are there to the Constitution?\n\n";
   
    cout<<"1.  27\n";
    cout<<"2.  28\n";
    cout<<"3.  29\n";
    cout<<"4.  30\n\n";
   
    cin>>a19;
    cout<<"\n\n";
    cin.ignore();
   
    if(b19==a19){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto q20;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q19;
    }
   
    //Question #20
    int a20, b20;
    b20 = 4;
    q20:
    cout<<"What are the 3 branches of Government?\n\n";
   
    cout<<"1.  Commercial, Executive, Legislative\n";
    cout<<"2.  Industrial, Commerical, Political\n";
    cout<<"3.  Religious, Legislative, Commercial\n";
    cout<<"4.  Judicial, Legislative, Executive\n\n";
   
    cin>>a20;
    cout<<"\n\n";
    cin.ignore();
   
    if(b20==a20){
    cout<<"Correct!\n\n";
    system("pause");
    system("cls");
    goto final;
    }
   
    else{
    cout<<"Incorrect.  Please try again.\n\n";
    system("pause");
    system("cls");
    goto q20;
    }
   
    //Final
    final:
    cout<<"Congratulations!  You've completed Section 1 of Sample Civics Questions!\n";
    cout<<"Press any Key to return to the main menu!\n\n\n\n";
    system("pause");
   
   
    return 0;
   
}
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE