Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   problem when program compiles (http://www.go4expert.com/forums/program-compiles-t9625/)

jimJohnson 28Mar2008 09:30

problem when program compiles
 
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.....

Code:


#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;

        do
        {
               
                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);
        Get_Letter_Grade(grade);
       

        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)
{
    Get_Letter_Grade(grade);
    number = Convert_Let_to_Num(number);
    sum = sum + number;
    count = count + 1;
}
gpa = sum / classes;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

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

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.


All times are GMT +5.5. The time now is 09:15.