1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

problem when program compiles

Discussion in 'C++' started by jimJohnson, Mar 28, 2008.

  1. jimJohnson

    jimJohnson New Member

    Mar 4, 2008
    Likes Received:
    Trophy Points:
    I am having a problem finishing a program....I must have some errors just not able to figure them out...Any help would be incredibly appreciated

    my code is.....

    #include <iostream>
    #include <string>
    using namespace std;
    int Get_Name_and_Num_Classes(string& name, int classes);
    double Calculate_GPA(char& grade, int number);
    void Get_Letter_Grade(char& grade);
    int Convert_Let_to_Num(char grade);
    void Print_Results(string name, double gpa);
    int main()
    	string name;
    	int classes = 0, sum = 0, number = 0;
    	char grade = ' ';
    	double gpa = 0.0;
    	cout << "Programmed by Bryan Kruep";
    	cout << endl << endl << "Type xxx for the name to Exit" << endl << endl;
    		name = Get_Name_and_Num_Classes(name, classes);
    		if (name != "xxx")
    			gpa = Calculate_GPA(grade, number);
    		Print_Results(name, gpa);
    	}while (name != "xxx");
    	classes = Get_Name_and_Num_Classes(name, classes);
    	return 0;
    int Get_Name_and_Num_Classes(string& name, int classes)
    	cout << "Enter the student's last name: ";
    	cin >> name;
    	cout << endl << "How many classes taken: ";
    	cin >> classes;
    	return (classes);
    double Calculate_GPA(char& grade, int number)
    	int count = 1, classes = 0;
    	double gpa = 0.00, sum = 0.00;
    	while (count <= classes)
        number = Convert_Let_to_Num(number);
        sum = sum + number;
        count = count + 1;
    gpa = sum / classes;
    return gpa;
    void Get_Letter_Grade(char& grade)
    	int count = 0;
    	cout << endl << endl << "Enter letter grade " << count << ": ";
    	cin >> grade;
    int Convert_Let_to_Num(char grade)
    	int number;
    	if ((grade == 'a') || (grade == 'A'))
    		number = 4;
    	if ((grade == 'b') || (grade == 'B'))
    		number = 3;
    	if ((grade == 'c') || (grade == 'C'))
    		number = 2;
    	if ((grade == 'd') || (grade == 'D'))
    		number = 1;
    	if ((grade == 'f') || (grade == 'F'))
    		number = 0;
    	return (number);
    void Print_Results(string name, double gpa)
    	cout << "Student " << name << " has a semester GPA of " << gpa << endl << endl;

    The output should be.....

    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


    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.

Share This Page