c++ program help Write a program that the user is prompted for 10 test scores. 0
ID: 3714916 • Letter: C
Question
c++ program help
Write a program that the user is prompted for 10 test scores.
0 to 100 points each score.
Open a file for output, called savedTestScores.txt.
Write a loop that prompts the user for the 10 test scores.
Each
time a test score is entered by the user, write the test score to savedNames file.
And save
each
test score to an array, called arrayTestScores.
Close the file.
Using the scores stored in the array,
write
a loop that reads through the array to determine the minimum, maximum and average test scores.
Print out the minimum, maximum and average test scores.
Are the scores written to the file ?
Explanation / Answer
Hi Dear,
Please find my implementation.
#include <fstream>
#include<iostream>
using namespace std;
int main ()
{
int n=10;
double score;
double arr[10];
double minimum,maximum,avg;
cout<<"Enter test score ";
for(int i=0;i<10;i++)
{
std::ofstream file_obj ("savedTestScores.txt", std::ofstream::app);
cin>>score;
arr[i]=score;
file_obj << score;
file_obj<<endl;
file_obj.close();
}
minimum=arr[0];
maximum=arr[0];
double sum=0;
for(int i=0;i<10;i++)
{
if(arr[i]>maximum)
{
maximum=arr[i];
}
else if(arr[i]<minimum)
{
minimum=arr[i];
}
sum=sum+arr[i];
}
avg=sum/10;
cout<<"Minimum score: "<<minimum<<endl;
cout<<"Maximum score: "<<maximum<<endl;
cout<<"Average score: "<<avg<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.