Ask Question
15 January, 09:19

What will the following segment of code output? Assume the user enters a grade of 90 from the keyboard. cout <> test_score;

+1
Answers (1)
  1. 15 January, 10:35
    0
    Complete Question:

    What will the following segment of code output?

    Assume the user enters a grade of 90 from the keyboard.

    cout << "Enter a test score: ";

    cin >> test_score;

    if (test_score < 60);

    cout << "You failed the test!" << endl;

    if (test_score > 60)

    cout << "You passed the test!" << endl;

    else

    cout << "You need to study for the next test!";

    Answer:

    You failed the test!

    You passed the test!

    Explanation:

    With the assumption that test_score has been declared as an int variable

    The output of: You failed the test! You passed the test! May be unexpected since the test_score is greater than 90 so it looks like the code has a logical error somewhere.

    This error is as a result of putting a semi colon at then end of the first if statement if (test_score < 60);

    An if statement does not end a thought as such there should'nt be a semi colon ending it. Take the semi-colon out and the program will give the expected output of You passed the test! since test_score of 90 is greater than 60
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What will the following segment of code output? Assume the user enters a grade of 90 from the keyboard. cout test_score; ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers