Hey everyone.. I'm having a little problem with something I'm writing for a class.. I'm supposed to use while and a nested IF statement in the solution, but every time I run it I get the following back:

Run-Time Check Failure #3 - The variable 'A' is being used without being defined.

Here's the code:

#include <iostream>
using namespace std;
void main()
{
	int TotalAssignments;
	char Assignment, A, B, C, D, F;
	int GPA;
	int Counter=0;
	int Sum=0;

			cout << "Total number of completed assignments this quarter?\n";
			cin >> TotalAssignments;

	while  (Counter < TotalAssignments)
	{
			Counter = Counter + 1;
			cout << "Assignment grade?\n";
			cin >> Assignment;
			if (Assignment = A)
			{
				A = 4;
			}
			else
			{
				if (Assignment = B)
				{
					B = 3;
				}
				else
				{
					if (Assignment = C)
					{
						C = 2;
					}
					else
					{
						if (Assignment = D)
						{
							D = 1;
						}
						else
						{
							if (Assignment = F)
							{
								F = 0;
							}
						}
					}
				}
			}
				Sum = Sum + Assignment;
	}
			GPA = Sum/TotalAssignments;
			cout << "Score average is.. " << GPA << "...\n";

Ideas..? :(

It looks like you are using the assignment operator (=) in the if statements rather than the comparison for equality operator (==):

if (Assignment = A)

Also it appears that you are treating charaters as integers:

if (Assignment = A)

rather than

if (Assignment == 'A')

which is what I am guessing you mean?

Hey everyone.. I'm having a little problem with something I'm writing for a class.. I'm supposed to use while and a nested IF statement in the solution, but every time I run it I get the following back:

Run-Time Check Failure #3 - The variable 'A' is being used without being defined.

Well, where did you assign a value to the variable A so you can use if (Assignment = A) Also, check you book for the difference between = and ==

See this about your void main(). I hope your instructor didn't teach you that.

lol.. that was my problem, VernonDozier.. Thanks.

WaltP, It's not a C++ class.. kinda annoying too.. it's Problem Solving With C++. So, doesn't talk much about the prograaming.. just tries to explain in a very basic way. I'll read up on the void main () though. The teacher basically gave us programs to copy and they always used the void main () so yeah.. :( Thanks for the info though.

Well, now it takes the input of the letters without giving me the error, but spits out a weird number.. typed 3 for total assignments, A, B, B.. then the output was:

Total number of completed assignments this quarter?
3
Assignment grade?
A
Assignment grade?
B
Assignment grade?
B
Score average is.. 44...
Press any key to continue . . .

?? That's definitely not an average of 4, 3, and 3..

Nevermind.. I figured out the problem with the averaging.. I wasn't actually assigning the IF statement variables to Assignment for the calculation so it wasn't doing it properly.

#include <iostream>
using namespace std;
void main()
{
	int TotalAssignments;
	char Assignment;
	int GPA;
	int Counter=0;
	int Sum=0;

			cout << "Total number of completed assignments this quarter?\n";
			cin >> TotalAssignments;

	while  (Counter < TotalAssignments)
	{
			cout << "Assignment grade?\n";
			cin >> Assignment;
			if (Assignment == 'A')
			{
				Assignment = 4;
			}
			else
			{
				if (Assignment == 'B')
				{
					Assignment = 3;
				}
				else
				{
					if (Assignment == 'C')
					{
						Assignment = 2;
					}
					else
					{
						if (Assignment == 'D')
						{
							Assignment = 1;
						}
						else
						{
							if (Assignment == 'F')
							{
								Assignment = 0;
							}
						}
					}
				}
			}
				Sum = Sum + Assignment;
				Counter = Counter + 1;
	}
			GPA = Sum / TotalAssignments;
			cout << "Score average is.. " << GPA << "...\n";
}

Works now. :) Thanks for the pointers, VernonDozier and WaltP.

This question has already been answered. Start a new discussion instead.