0

Hey I'm working on this program that tests you on a few questions. I enter the answer to one and it comes back and displays correct. For some reason though when the next question comes on it already comes back with a response saying the answer was incorrect. Here's the code.

string metals = "metals";
    string userresponse221;
    cout << "\n22.  Ionic compounds are usually formed between which two groups of elements?\n1:\t";
    cin >> userresponse221;
    
    if (userresponse221 == metals)
    {
                cout << "Correct" << endl;
    }
    else
    {
        cout << "Incorrect" << endl;
    }
    
    cout << "2: \t";
    string nonmetals = "nonmetals";
    string userresponse222;
    cin >> userresponse222;
    if (userresponse222 == nonmetals)
    {
                cout << "Correct" << endl;
    }
    else
    {
        cout << "Incorrect" << endl;
    }
    
    
    cout << "\nName the following compounds:\n";
    
    
    
    // Question 23
    string answer23 = "lithium nitride";
    string userresponse23;
    cout << "\n23.  Li3N:\n\t";
    getline(cin,userresponse23);
    if (userresponse23 == answer23)
    {
                 cout << "Correct" << endl;

    }
    else
    {
                 cout << "Incorrect" << endl;
    }

If anyone sees anything wrong I'd truly appreciate it.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by theashman88
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.