I apologize if this does not sound clear. I will show the assignment and what the output is supposed to look like along with the code that I have so far.....My problem is pretty much
typing this xxx to exit....I have always used numbers for this so a string would be new to me....we are not allowed to exit(1) and was just seeing if anyone had any ideas for this

By the way I know it has quite a few errors right now but what I am really wanting to fix is the "type xxx to exit"....I have always used numbers for statement to exit such as while (x>=0) for it being type a negative to exit (just an example) so I know what I am doing for the most part but really didn't find a whole lot of help in the book....I hope this makes more sense

Instructions.........

Write a program to compute a student’s GPA for one semester. It should ask the user for the student’s last name, and how many classes were taken during the semester. It will then ask the user to type in the letter grade for each class and print the GPA to the screen.

The program should continue doing this until the user types an xxx for the last name.
Program Requirements
• To make the program easier, assume all classes are 3 credits.
• There should be two digits of precision
• You should have the following functions:
• Get_Name_and_Num_Classes - This function asks the user to type in their name and the number of classes taken
• Calculate_GPA - This function computes GPA. It does this by looping. It call Get_Letter_Grade to allow the user to enter a valid letter grade and then it calls Convert_Let_to_Num. It uses this information to compute the GPA. It returns the GPA. (you should be able to determine the formal parameters)
• Get_Letter_Grade – This function is a void function. It asks the user to type in a letter grade, and then makes sure that the letter grade is valid. It must be an A, B, C, D, or F. You should be able to determine the formal parameters.
• Convert_Let_to_Num – Takes in a letter grade and converts it to its number equivalent (A–4, B–3, C–2, D–1, F–0) It should return the number equivalent.
• Print_Results - This prints all results to the screen. It should not return a value.


The output should say:

Programmed by <your name>

Type xxx for the name to exit

Enter the student's last name: Mickey
How many classes taken: 3

Enter letter grade 1: a
Enter letter grade 2: B
Enter letter grade 3: b

Student Mickey has a semester GPA of 3.33

Enter the student's last name: Goofy
How many classes taken: 5

Enter letter grade 1: c
Enter letter grade 2: C
Enter letter grade 3: d
Enter letter grade 4: b
Enter letter grade 5: a

Student Goofy has a semester GPA of 2.40

Enter the student's last name: Donald
How many classes taken: 2

Enter letter grade 1: c
Enter letter grade 2: B


Student Donald has a semester GPA of 2.50

Enter the student's last name: Minnie
How many classes taken: 4

Enter letter grade 1: A
Enter letter grade 2: A
Enter letter grade 3: B
Enter letter grade 4: A

Student Mickey has a semester GPA of 3.75

Enter the student's last name: xxx


Here is my code....

#include <iostream>
using namespace std;
string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
char Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);

int main()
{
	string name;
	int count = 1;
	int classes;
	char grade;
	double gpa;


	cout << "Programmed by Jim Johnson";
	cout << endl << endl << "Type xxx for the name to Exit";

	do
	{
		cout << endl << endl << "Enter the student's last name: ";
		name = Get_Name_and_Num_Classes(classes, name);

		if (name != "xxx")
		{
			cout << endl << "How many classes taken: ";
			classes = Get_Name_and_Num_Classes(classes, name);

		}while (count <= classes)
			
				cout << endl << endl << "Enter letter grade " << count << ": ";
				grade = Get_Letter_Grade("grade");
				count ++;

			Print_Results(name, gpa);
			}while (name != "xxx");





			return 0;
}

char Get_Letter_Grade(char grade)
{
	
cin >> grade;
		
	return grade;
}

double Calculate_GPA()
{
	double gpa;
	


	return (gpa);

}



string Convert_Let_to_Num(char grade)
{
	int number;
	if ((char == 'a') || (char == 'A'))
	{
		number == 4;
	}
	else if ((char == 'b') || (char == 'B'))
	{
		number == 3;
	}
	else if ((char == 'c') || (char == 'C'))
	{
		number == 2;
	}
	else if ((char == 'd') || (char == 'D'))
	{
		number == 1;
	}
	else
		number == 0;

	return (number);
}

void Print_Results(string name, double gpa)
{
	cout << "Student " << name << " has a semester GPA of " << gpa;
}

You could approach this with a while loop, reading the name one time before the loop, then at the bottom of the loop

cout << "Programmed by Jim Johnson";
	cout << endl << endl << "Type xxx for the name to Exit";

        cout << endl << endl << "Enter the student's last name: ";
	name = Get_Name_and_Num_Classes(classes, name);

       while ( name != "xxx" )
      {
           //rest of processing for student

           cout << endl << endl << "Enter the student's last name: ";
	   name = Get_Name_and_Num_Classes(classes, name);
      }

It would help readers of your code if you also spend a bit more time on formatting.

tried that and still getting some errors.....

c:\documents and settings\don & diane kruep\desktop\project 04\p04.cpp(28) : error C2664: 'Get_Name_and_Num_Classes' : cannot convert parameter 1 from 'int' to 'std::string &'
1>

c:\documents and settings\don & diane kruep\desktop\project 04\p04.cpp(30) : error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1> could be 'built-in C++ operator!=(const char [4], const char [4])'
1> while trying to match the argument list '(std::string, const char [4])'

1>c:\documents and settings\don & diane kruep\desktop\project 04\p04.cpp(30) : fatal error C1903: unable to recover from previous error(s); stopping compilation

here is my code.....

#include <iostream>
using namespace std;
string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
char Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);

int main()
{
	string name;
	int count = 1;
	int classes;
	char grade;
	double gpa;


	cout << "Programmed by Jim Johnson";
	cout << endl << endl << "Type xxx for the name to Exit";

	do
	{
		cout << endl << endl << "Enter the student's last name: ";
		name = Get_Name_and_Num_Classes(classes, name);

		while (name != "xxx")
		{
			cout << endl << "How many classes taken: ";
			classes = Get_Name_and_Num_Classes(classes, name);

		}while (count <= classes)
			
				cout << endl << endl << "Enter letter grade " << count << ": ";
				grade = Get_Letter_Grade("grade");
				count ++;

				gpa = Calculate_GPA(char grade, count++);

				 

			Print_Results(name, gpa);
			}while (name != "xxx");





			return 0;
}

char Get_Letter_Grade(char grade)
{
	
cin >> grade;
		
	return grade;
}

double Calculate_GPA()
{
	int total_grades
	double gpa;

	total_grades = 
	
	

	return (gpa);

}



string Convert_Let_to_Num(char grade)
{
	int number;
	if ((char == 'a') || (char == 'A'))
	{
		number == 4;
	}
	else if ((char == 'b') || (char == 'B'))
	{
		number == 3;
	}
	else if ((char == 'c') || (char == 'C'))
	{
		number == 2;
	}
	else if ((char == 'd') || (char == 'D'))
	{
		number == 1;
	}
	else
		number == 0;

	return (number);
}

void Print_Results(string name, double gpa)
{
	cout << "Student " << name << " has a semester GPA of " << gpa;
}

tried that and still getting some errors.....

c:\documents and settings\don & diane kruep\desktop\project 04\p04.cpp(28) : error C2664: 'Get_Name_and_Num_Classes' : cannot convert parameter 1 from 'int' to 'std::string &'
1>

The function Get_Name_and_Num_Classes has the first parameter defined as a string, you are passing an int instead.

looks like I got that fixed...still got errors with my original question

1>c:\documents and settings\don & diane kruep\desktop\project 04\p04.cpp(30) : error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1> could be 'built-in C++ operator!=(const char [4], const char [4])'
1> while trying to match the argument list '(std::string, const char [4])'

#include <iostream>
using namespace std;
string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
char Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);

int main()
{
	string name;
	int count = 1;
	int classes;
	char grade;
	double gpa;


	cout << "Programmed by Jim Johnson";
	cout << endl << endl << "Type xxx for the name to Exit";

	do
	{
		cout << endl << endl << "Enter the student's last name: ";
		name = Get_Name_and_Num_Classes(name, classes);

		while (name != "xxx")
		{
			cout << endl << "How many classes taken: ";
			classes = Get_Name_and_Num_Classes(name, classes);

		}while (count <= classes)
			
				cout << endl << endl << "Enter letter grade " << count << ": ";
				grade = Get_Letter_Grade("grade");
				count ++;

				gpa = Calculate_GPA(char grade, count++);

				 

			Print_Results(name, gpa);
			}while (name != "xxx");





			return 0;
}

char Get_Letter_Grade(char grade)
{
	
cin >> grade;
		
	return grade;
}

double Calculate_GPA()
{
	int total_grades
	double gpa;

	total_grades = 
	
	

	return (gpa);

}



string Convert_Let_to_Num(char grade)
{
	int number;
	if ((char == 'a') || (char == 'A'))
	{
		number == 4;
	}
	else if ((char == 'b') || (char == 'B'))
	{
		number == 3;
	}
	else if ((char == 'c') || (char == 'C'))
	{
		number == 2;
	}
	else if ((char == 'd') || (char == 'D'))
	{
		number == 1;
	}
	else
		number == 0;

	return (number);
}

void Print_Results(string name, double gpa)
{
	cout << "Student " << name << " has a semester GPA of " << gpa;
}

Read the error
Look at the line in question
Look at the variable types
Correct the problem

It's extremely obvious if you just look at it. Took me all of 2 seconds and I didn't even write the program.

I wouldn't say it's extremely obvious. but if the OP had used better vertical whitespace among program elements, it would be easier to notice.

If you're gonna use strings, don't forget the #include <string> Then you can go to work on the real errors.

it almost looks like my book is saying like either


while(!"xxx" = name) or


while(!name = "xxx")


but tried them both and both wrong

this formatted any better??????

#include <iostream>
#include <string>
using namespace std;
string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
void Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);

int main()
{
	string name, xxx;
	int count = 1;
	int classes;
	char grade;
	double gpa;

	cout << "Programmed by Jim Johnson";
	cout << endl << endl << "Type xxx for the name to Exit";

	do
	{
		cout << endl << endl << "Enter the student's last name: ";
		name = Get_Name_and_Num_Classes(name, classes);

		while (!"xxx" = name)
		{
			cout << endl << "How many classes taken: ";
			classes = Get_Name_and_Num_Classes(name, classes);

		}while (count <= classes)
			
		cout << endl << endl << "Enter letter grade " << count << ": ";
		grade = Get_Letter_Grade("grade");
		count ++;
		
		gpa = Calculate_GPA(char grade, count++);

		Print_Results(name, gpa);
	}while (name != "xxx");

	return 0;
}

void Get_Letter_Grade(char grade)
{
	
cin >> grade;
		
	return grade;
}

double Calculate_GPA()
{
	int total_grades
	double gpa;

	total_grades = 
	
	return (gpa);

}

string Convert_Let_to_Num(char grade)
{
	int number;
	if ((char == 'a') || (char == 'A'))
	{
		number == 4;
	}
	else if ((char == 'b') || (char == 'B'))
	{
		number == 3;
	}
	else if ((char == 'c') || (char == 'C'))
	{
		number == 2;
	}
	else if ((char == 'd') || (char == 'D'))
	{
		number == 1;
	}
	else
		number == 0;

	return (number);
}

void Print_Results(string name, double gpa)
{
	cout << "Student " << name << " has a semester GPA of " << gpa;
}

sorry messed up tags

#include <iostream>
#include <string>
using namespace std;
string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
void Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);

int main()
{
	string name, xxx;
	int count = 1;
	int classes;
	char grade;
	double gpa;

	cout << "Programmed by Jim Johnson";
	cout << endl << endl << "Type xxx for the name to Exit";

	do
	{
		cout << endl << endl << "Enter the student's last name: ";
		name = Get_Name_and_Num_Classes(name, classes);

		while (!"xxx" = name)
		{
			cout << endl << "How many classes taken: ";
			classes = Get_Name_and_Num_Classes(name, classes);

		}while (count <= classes)
			
		cout << endl << endl << "Enter letter grade " << count << ": ";
		grade = Get_Letter_Grade("grade");
		count ++;
		
		gpa = Calculate_GPA(char grade, count++);

		Print_Results(name, gpa);
	}while (name != "xxx");

	return 0;
}

void Get_Letter_Grade(char grade)
{
	
cin >> grade;
		
	return grade;
}

double Calculate_GPA()
{
	int total_grades
	double gpa;

	total_grades = 
	
	return (gpa);

}

string Convert_Let_to_Num(char grade)
{
	int number;
	if ((char == 'a') || (char == 'A'))
	{
		number == 4;
	}
	else if ((char == 'b') || (char == 'B'))
	{
		number == 3;
	}
	else if ((char == 'c') || (char == 'C'))
	{
		number == 2;
	}
	else if ((char == 'd') || (char == 'D'))
	{
		number == 1;
	}
	else
		number == 0;

	return (number);
}

void Print_Results(string name, double gpa)
{
	cout << "Student " << name << " has a semester GPA of " << gpa;
}

I'd use 4 spaces instead of TABs. Too much indentation is just as bad as none. But that's my personal preference.

anyone besides walt can you give me some pointers on this problem....nothing against you walt but i think you are too advanced for helping a beginner

This while (!"xxx" = name) is seriously not gonna work, for several reasons.
First, using the assignment operator won't give you a comparison, and usually results in a constant true value. Second, you can't assign to the literal string. Third, putting the NOT operator in front of the literal string...I got no clue how bad that is.

Now that you have the string library included, you can go back to your original loop test while (name != "xxx") - this works now and expresses what I think you want to say.

As to formatting, I was thinking of better separating portions at the beginning into logical groups, like:

#include <iostream>
#include <string>
using namespace std;

string Get_Name_and_Num_Classes(string name, int classes);
double Calculate_GPA();
void Get_Letter_Grade(char grade);
double Convert_Let_to_Num();
void Print_Results(string name, double gpa);

int main( )
......

So, with the while loop restored, you have a couple compiler errors to fix. Read the error messages, look to the lines they point at, make sure you're using the correct data types for your function arguments and to store return values to.

This article has been dead for over six months. Start a new discussion instead.