#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
string name;
float grade1, grade2, grade3, avg, sum;
int count;
sum =0;
count = 0;
ifstream inputFile;
inputFile.open("data.txt");
if(inputFile.fail())
{
cout<<"There is something wrong with the file\n";
return 0;
}//end if
getline(inputFile,name);
cout<<fixed<<setprecision(1);
cout<<"For student"<<name<<"grades are the following:\n";
inputFile>>grade1;
while(!inputFile.eof())
{
if (grade1<0 || grade1 >100)
cout <<"Grade"<<grade1<<"will not be counted.\n";
else
{sum += grade1;
count +=1;
}//end else
inputFile>>grade1;
} // end while
getline(inputFile,name);
cout<<fixed<<setprecision(1);
inputFile>>grade2;
if(grade2<0 || grade2 >100)
cout<<"Grade"<<grade2<<"will not be counted.\n";
else
{sum += grade2;
count +=1;
} //end else
getline(inputFile,name);
cout<<fixed<<setprecision(1);
inputFile>>grade3;
if(grade3<0 || grade3 >100)
cout<<"Grade"<<grade3<<"will not be counted.\n";
else
{sum += grade3;
count +=1;
} //end else
inputFile.close();
avg = sum/count;
cout<<fixed<<setprecision(1);
cout<<"For student"<<name<<"grades are the following:\n";
cout<<setw(10)<<grade1<<endl;
cout<<setw(10)<<grade2<<endl;
cout<<setw(10)<<grade3<<endl;
cout<<endl<<"The average is "<<avg<<endl;
system("pause");
return 0;
}
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>
Thanks,
PsychoCoder

New Topic/Question
Reply



MultiQuote


|