In: Computer Science
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Code:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int marks,i;
double total;/*Declaring variables*/
ofstream File("mean.txt");/*file*/
cout<<"Enter the marks of 5 tests:
"<<endl;
File<<"Test Scores\n";/*Writing into the
file*/
for(i=1;i<=5;i++)
{
cin>>marks;/*Reading marks
from the user user*/
total+=marks;/*Calculating the
total*/
File<<marks<<"\n";/*Writing marks into the file*/
}
cout<<"Mean:"<<total/5;/*Printing mean on
to the screen*/
File<<"Mean:"<<total/5;/*Writing mean into
the file*/
}
Output:
Output in the file:
Indentation: