Ask Question
30 November, 03:49

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. 30 November, 07:19
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers