Assuming that a user enters 64 as his marks obtained, what is the output of the following code snippet? int main() { int score = 0; cout << "Enter your score: "; cin >> score; if (score < 40) { cout << "F" << endl; } else if (score < 50) { cout << "D" << endl; } else if (score < 60) { cout << "C" << endl; } else if (score < 70) { cout << "B" << endl; } else if (score < 80) { cout << "B+" << endl; } else { cout << "A" << endl; } return 0; }
a) D b) C c) B d) A
Answer is option C) B
Here, this program is executing if else if statements for finding out the grade according to user input.
When a user enters 64,
1-> if(score < 40), then it will not be true, so next will be implemented.
2-> else if (score < 50), then it will not be true, so next will be implemented.
3-> else if (score < 60), then it will not be true, so next will be implemented.
4-> else if (score < 70), since, score is 64, so this statement will be true, and hence, cout << "B" will be implemented.
Which will give us output B.
So, answer is C) B
Get Answers For Free
Most questions answered within 1 hours.