1.
Write a program that asks for
five test scores. The program should calculate the average test score and
display it. The number displayed should be formatted in fixed-point notation,
with one decimal point of precision. (use of while loop is optional)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int s1,s2,s3,s4,s5;
double avg,sum;
cout<<"Enter first test score = ";
cin>>s1;
cout<<"Enter 2nd test score = ";
cin>>s2;
cout<<"Enter 3rd test score = ";
cin>>s3;
cout<<"Enter 4rth test score = ";
cin>>s4;
cout<<"Enter fifth test score = ";
cin>>s5;
sum=s1+s2+s3+s4+s5;
avg=sum/5;
cout<<"The average= "<<setprecision(1)<<fixed<<avg<<endl;
return 0;
}
No comments:
Post a Comment