5 Replies - 1147 Views - Last Post: 02 April 2011 - 03:31 AM Rate Topic: -----

#1 cheez   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-April 11

I keep getting error C2784, please help?

Posted 01 April 2011 - 08:39 PM

I have the following code to create a grader in which it calculates the average and outputs whether a student received an A, B, C, or D.

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

//Program name: Grader

int main()
{
	string garbage;
	int Participation, Lab, Project, Midterm1, Midterm2, Final;
	double FinalGrade;
	string Firstname, Lastname;
	ifstream inData;
	inData.open("G:\\C++\\Project 3\\prj3Indata.txt");

	inData>>garbage>>Firstname>>Lastname;
	inData>>garbage>>Participation;
	inData>>garbage>>Lab;
	inData>>garbage>>Project;
	inData>>garbage>>Midterm1>>Midterm2;
	inData>>garbage>>Final;
	inData>>FinalGrade;
	

	FinalGrade = (Participation*0.05) + (Lab*0.10) + (Project*0.20) + (Midterm1*0.15) + (Midterm2*0.15) + (Final*0.35);

	cout<<"What is your name?";
	cin>>Firstname>>Lastname<<endl
	cout<<"Participation =";
	cin>>Participation<<endl
	cout<<"Lab =";
	cin>>Lab<<endl
	cout<<"Project =";
	cin>>Project<<endl
	cout<<"Midterm1 and Midterm2 =";
	cin>>Midterm1<<Midterm2<<endl
	cout<<"Your final grade is";

	if (FinalGrade >= 90)
		cout<<"A"; 
	else if (FinalGrade >= 80)
		cout<<"B";
	else if (FinalGrade >= 70)
		cout<<"C";
	else if (FinalGrade >= 60)
		cout<<"D";
	else 
		cout<<"F";

}
	inData.close();




I've tried researching this error everywhere but no luck. Could you please help me fix what is wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: I keep getting error C2784, please help?

#2 #define   User is offline

  • Cannot compute!
  • member icon

Reputation: 1868
  • View blog
  • Posts: 6,763
  • Joined: 19-February 09

Re: I keep getting error C2784, please help?

Posted 01 April 2011 - 09:21 PM

You have several lines like this:

cin>>Firstname>>Lastname<<endl



Data is coming from the console in cin stream and entered into variables using the >> operator. You have incorectly added the << operator and an endl, and have no semicolon.

At the end of main() a call to a function is made outside of a function which is incorrect.
52	}
53	    inData.close();


Was This Post Helpful? 0
  • +
  • -

#3 cheez   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-April 11

Re: I keep getting error C2784, please help?

Posted 01 April 2011 - 09:31 PM

Yes, I figured it out already. Thank you though :)
Was This Post Helpful? 0
  • +
  • -

#4 #define   User is offline

  • Cannot compute!
  • member icon

Reputation: 1868
  • View blog
  • Posts: 6,763
  • Joined: 19-February 09

Re: I keep getting error C2784, please help?

Posted 01 April 2011 - 09:38 PM

View Postcheez, on 02 April 2011 - 06:31 AM, said:

Yes, I figured it out already. Thank you though :)


Ok, well done! :)
Was This Post Helpful? 0
  • +
  • -

#5 cheez   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-April 11

Re: I keep getting error C2784, please help?

Posted 01 April 2011 - 10:08 PM

Can I ask one more question?
I'm pretty sure my code was correct because it worked, but then I changed some numbers on the .txt file and then changed them back to the originals, but when I tried to run the program again it started the debugging process but a screen never came up then it said it exited. Why is this?
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: I keep getting error C2784, please help?

Posted 02 April 2011 - 03:31 AM

You will have to post your most recent code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1