Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program that repeatedly prompts the user to enter a student

ID: 3583328 • Letter: W

Question

Write a complete C++ program that repeatedly prompts the user to enter a student's scores until -1 is the program should stop reading students' scopes. It then calculates and displays the total number of scores entered and the average score. Use proper programming styles (e.g. - add comments; indent and align the statements). Enter a score: 80 Enter a score: 70 Enter a score: 60 Enter a score: - 1 Total number of scores entered = 3 Average score = 70 # include using namespace stel; in main() {cout 80; cout

Explanation / Answer

#include <iostream>
using namespace std;

//main function to calculate average scores
int main()
{
    //variables to cal average
    bool flag=true;
    int scores[100];
    int count=0;
    int tmp;
    double averageScore=0.0;
  
    //loop until user enters -1
    do
    {
        //prompt user to enter score
        cout << "Enter a score: ";
        cin>>tmp;
      
        //check if user has entered -1
        //if yes, store in array
        if(tmp!=-1)
        {
            scores[count]=tmp;
            averageScore+=tmp;
            count++;
        }
        else
        flag=false;
    }while(flag);
  
    //display scores entered and average score
   cout<<" Total number of scores entered: "<<count;
   cout<<" Average Score: "<<averageScore/count;
   cout<<endl;
   return 0;
}

Sample Output:

Enter a score: 80                                                                                                                                                                                  

Enter a score: 70                                                                                                                                                                                  

Enter a score: 60                                                                                                                                                                                  

Enter a score: -1                                                                                                                                                                                  

                                                                                                                                                                                                   

Total number of scores entered: 3                                                                                                                                                                  

Average Score: 70                                                                                                                                                                     

                           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote