Question

write a program using a while loop that asks a user to enter scores of exam...

write a program using a while loop that asks a user to enter scores of exam for each subject and calculate the total and average. in c++

Homework Answers

Answer #1

Code:

#include <iostream>
using namespace std;

int main()
{
int n, i;
float num[100], sum=0.0, average;

cout << "Enter the number of subjects: ";
cin >> n;

while (n > 6 || n <= 0)
{
cout << "Error..entered number for subjects count is exceeded: ";
cin >> n;
}

for(i = 0; i < n; ++i)
{
cout << i + 1 << ". Enter subject score: ";
cin >> num[i];
sum += num[i];
}

average = sum / n;
cout << "Total = "<<sum;
cout << "Average = " << average;

return 0;

}

Output:

Enter the number of subjects: 4

Enter subject score: 35

Enter subject score: 85

Enter subject score: 96

Enter subject score: 48

Total = 264

Average = 66

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a program that asks the User to enter a letter, then asks the user to...
write a program that asks the User to enter a letter, then asks the user to enter a sentence. the program will then print out how many time that letter occurred in the sentence. in C Language
Write a C program that asks the user to enter two integers x and n. Then...
Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. using printf scanf
Write a MATLAB while-loop code that asks a user to enter an integer number until its...
Write a MATLAB while-loop code that asks a user to enter an integer number until its factorial is smaller than 100.
Write a program that asks the user for the name of a file. The program should...
Write a program that asks the user for the name of a file. The program should display only the first five lines of the file’s contents. If the file contains less than five lines, it should display the file’s entire contents. by python using while loop
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
Write a Java program called Decision that includes a while loop to prompt the user to...
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail. Example of the expected output is as follows:
Write a program that asks the user to enter an odd number and prints out a...
Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is note: There is one space between the numbers in each line 1 3 5 1 3 1 If the user enters 9 the output is: 1 3 5 7 9 1 3 5 7 1 3 5 1 3 1 program language: C++
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
1) In Python Use a while loop to ask the user to enter a series of...
1) In Python Use a while loop to ask the user to enter a series of alphabets. The loop terminates when the user presses enter. Once the loop terminates, display the number of vowels and consonants entered by the user. Hint: keep a running count of the number of characters entered by the user. Keep a running count of the number of vowels. Total number of consonants = total number of characters - total number of vowels. Assume that the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT