Question

In: Computer Science

IN C++ Write a program that prompts the user to enter the number of students and...

IN C++

Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop.

Sample Output

Please enter the number of students:

4

Enter the student name:

Ben Simmons

Enter the score:

70

Enter the student name:

Carson Wentz

Enter the score:

80

Enter the student name:

Joel Embiid

Enter the score:

90

Enter the student name:

Bryce Harper

Enter the score:

75

Joel Embiid

score is 90

the average is 78.75

the difference is 11.25

Press any key to continue . . .

Solutions

Expert Solution

Explanation:

Here is the code which asks for the number of students from the user and then each student's score and name is asked and sum is taken for the scores and the highest score is also detected.

Then, average, highest score are printed and then difference of both is also printed.

Code:


#include <iostream>

using namespace std;

int main()
{
int n;
cout<<"Please enter the number of students: ";
cin>>n;
  
string name_highest = "";
int highest = -1;
  
int sum = 0;
  
int i=0;
  
while (i < n) {
  
string s;
int score;
  
getline(cin, s);
  
cout<<"Enter the student name: ";
getline(cin, s);
cout<<"Enter the score: ";
cin>>score;
sum+= score;
if(highest<score)
{
name_highest = s;
highest = score;
}
  
i++;
}
  
cout<<name_highest<<endl;
cout<<"score is "<<highest<<endl;
  
float avg = (float)sum/(float)n;
cout<<"the average is "<<avg<<endl;
  
cout<<"the difference is "<<(highest-avg)<<endl;

return 0;
}

output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

C++ [2] Write a program that prompts the user to enter a non-negative decimal number and...
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and a base in the range 2 <= base <= 16. Write a function multibaseOutput() that displays the number in the specified base. The program terminates when the user enters a number of 0 and a base 0. Run: Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 155 16     155 base 16 is 9B Enter...
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
In Java: Write a program that prompts the user to enter a positive number until the...
In Java: Write a program that prompts the user to enter a positive number until the user input a negative number. In the end, the program outputs the sum of all the positive numbers. You should use do-while loop (not while, not for). You cannot use break or if statement in the lab. Hint: if the program adds the last negative number to your sum, you can subtract the last number from the sum after the loop.
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
Use c# Create a program called ResortPrices that prompts the user to enter the number of...
Use c# Create a program called ResortPrices that prompts the user to enter the number of days for a resort stay. Then display the price per night and the total price. Nightly rates are R 500.00 for one or two nights, R 650.00 for three or four nights, R 850.00 for five, six or seven nights, and R 1500.00 for eight nights or more.
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Computer Architecture and Organization(c++) Write a C++ program that prompts the user to enter a hexadecimal...
Computer Architecture and Organization(c++) Write a C++ program that prompts the user to enter a hexadecimal value, multiplies it by ten, then displays the result in hexadecimal. Your main function should a) declare a char array b) call the readLn function to read from the keyboard, c) call a function to convert the input text string to an int, d) multiply the int by ten, e) call a function to convert the int to its corresponding hexadecimal text string, f)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT