(Concepts needed: conditional structure, sentinel controlled structure, and func
ID: 3628142 • Letter: #
Question
(Concepts needed: conditional structure, sentinel controlled structure, and function)Write a C++ program to calculate the average score for uncertain number of students.
Define variables – score, student_no and sum
Use sentinel controlled structure to do the following:
a. Ask user to input an integer as student score. Please do the error checking for the score. The
range of score is between 0 and 100. If the score is not in the range, please display an error
message and ask user to input a new score.
b. Add the valid score to sum
c. Repeat step a and b until user input a user defined sentinel value to stop the loop
Define a function to calculate the average - dividing sum by student_no. Please note that the average is float not integer.
Display the number of students, total points, and average (2 decimal places).
Explanation / Answer
// NOTE: I could have also checked whether the user input is integer type or not but I didn't do that. #include #include using namespace std; int main() { int student_no = 0; int sum = 0; int score = 0; cout > score; cin.ignore(); // eat the while (score != -1) { if (score > 100 || score < 0) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.