Our teacher made us make a program that computes midterm grade. I have made my code already. My problem now is that whenever i run my code, halfway through the end appears a debug error saying that i was using a variable(TotalCS) that isn't declared. but it is actually declared. So what should i do with this..

this is the part where i declared the variables:

double Quiz1, Quiz2, Quiz3;
      double NoOfLate, NoOfAbsences;
      double Project, TotalCS, MidtermExam;

its in this part where the debug error appears:

cout<<"Midterm Exam(40%):\n";
	cin>>MidtermExam;
	cout<<"Midterm Grade:\n";
	cout<<((TotalCS * 2) + MidtermExam)/3<<endl;

Not enough information. Since you're declaring TotalCS, I would assume that you have an error where TotalCS is declared in a scope that isn't visible at the time of that expression. However, I can't say for sure with so little code. Trim your program down to bare bones (without removing the error) and post it for us.

uhmm.. sorry.. didn't quite grasp what you mean..

but here's the code:

double Quiz1, Quiz2, Quiz3;
	double NoOfLate, NoOfAbsences;
	double Project, MidtermExam;
	double TotalCS;

	cout<<"\t\tGrading System\n\n";
	cout<<"Quiz 1:\n";
	cin>>Quiz1;
	cout<<"Quiz 2:\n";
	cin>>Quiz2;
	cout<<"Quiz 3:\n";
	cin>>Quiz3;
	cout<<"Average of Quizzes:\n";
	cout<<(Quiz1 + Quiz2 + Quiz3)/3<<endl;

	cout<<"Number of Late:\n";
	cin>>NoOfLate;
	cout<<"Number of Absences:\n";
	cin>>NoOfAbsences;
	cout<<"Project:\n";
	cin>>Project;
	cout<<"TotalCS(60%):\n";
	cout<<(Quiz1 + Quiz2 + Quiz3 +(NoOfLate + NoOfAbsences + Project))/2<<endl;

	cout<<"Midterm Exam(40%):\n";
	cin>>MidtermExam;
	cout<<"Midterm Grade:\n";
	cout<<((MidtermExam * .40)+ (TotalCS * .60))<<endl;

the problem is.. when its about to display the computed midterm grade.. debug error appears.. saying that variable TotalCS is being used without being initialized.. and TotalCS is not an input but is also an output..

What did you expect to be displayed? Where did you put that value into TotalCS? Did I miss it?

i was expecting that the computed midterm grade would be displayed.. unfortunately it didn't.

my problem now is, how do i initialized the TotalCS?(TotalCS is not an input)

i cant realLy think well right now.. pls heLp..

At some point in your code, you need to assign a value to TotalCS.

TotalCS = <something>;

So far, all you're doing is inputting values into variables and printing out expressions. Either you've been asleep in your course, or you're just in a panic now. Take a deep breath, and think through what you're doing. Everything will go a good bit easier as a result. :)

is the totalCS means total class standing? because if thats what you mean you should put totalCS = q1 + q2 and so on...

uhmm.. sorry.. didn't quite grasp what you mean..

but here's the code:

double Quiz1, Quiz2, Quiz3;
	double NoOfLate, NoOfAbsences;
	double Project, MidtermExam;
	double TotalCS;

	cout<<"\t\tGrading System\n\n";
	cout<<"Quiz 1:\n";
	cin>>Quiz1;
	cout<<"Quiz 2:\n";
	cin>>Quiz2;
	cout<<"Quiz 3:\n";
	cin>>Quiz3;
	cout<<"Average of Quizzes:\n";
	cout<<(Quiz1 + Quiz2 + Quiz3)/3<<endl;

	cout<<"Number of Late:\n";
	cin>>NoOfLate;
	cout<<"Number of Absences:\n";
	cin>>NoOfAbsences;
	cout<<"Project:\n";
	cin>>Project;
	cout<<"TotalCS(60%):\n";
	cout<<(Quiz1 + Quiz2 + Quiz3 +(NoOfLate + NoOfAbsences + Project))/2<<endl;

	cout<<"Midterm Exam(40%):\n";
	cin>>MidtermExam;
	cout<<"Midterm Grade:\n";
	cout<<((MidtermExam * .40)+ (TotalCS * .60))<<endl;

the problem is.. when its about to display the computed midterm grade.. debug error appears.. saying that variable TotalCS is being used without being initialized.. and TotalCS is not an input but is also an output..

You haven't given the variable TotalCS a starting point, right now you're just declaring it which allocates the memory for that variable, but there isn't actually anything in there so when you try to use it in a calculation the machine doesn't know what to do.

Try changing it to

double TotalCS = 0.00;

and see if that removes the error (I don't know what TotalCS is actually supposed to be, so obviously you need to change that yourself.

Post back if there are more problems (:

commented: Was it necessary to repeat for the third time the exact same fix in this 4 month old thread? -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.