Grade Calculator Error

Source Code with Grade Calculator

Page 1 of 1

2 Replies - 1525 Views - Last Post: 06 April 2009 - 05:01 PM Rate Topic: -----

#1 rtm1974   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 09

Grade Calculator Error

Post icon  Posted 06 April 2009 - 04:54 PM

#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 => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Grade Calculator Error

#2 Sadaiy   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 03-October 08

Re: Grade Calculator Error

Posted 06 April 2009 - 04:59 PM

What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Grade Calculator Error

Posted 06 April 2009 - 05:01 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1