Subscribe to hushbaby's Blog        RSS Feed
-----

I don't know whats wrong with this code?

Icon Leave Comment
Three regular functions, one for getting the data on the four students, one for calculating the GPA, and one for the output. One of the functions must be recursive.
Project Requirements:
1. Find a function to use recursion in and use it.
2. Do not include any unused header files.
3. Grades can be entered in upper or lower case.
4. The input will be A, B, C, D, & F. Standard letter grades.
5. GPA’s are 4.0, 3.0, 2.0, 1.0 & 0.0 respectively
6. Format output to 3 decimal points (i.e. 3.500, 2.750).
7. There will be only four students (Freddie, Jane, Jonathan, & Mary)
8. Each student will have 5 grades to enter.
9. The final output for the GPA’s will be in columnar output.
10. Only catch common incorrect letter grades (i.e. K, Z, O, etc…).
These are the requirements and I think I followed them, but the intructor said my its incomplete. Can anyone tell me whats wrong here? Thanks
 

#include <iostream>  //cin & cout
#include <conio.h>  //getch
#include <iomanip>  //setiosflags & setprecision

using namespace std;

//declarations for the functions
float fGetGrades(int); //The recursive function...
void fOutputGPA(const char *[], float[]);
inline float fCalculateGPA(float fGrades) {return fGrades / 5.0f;};
inline void ProgramHeader() {cout << "Programmed by me.\n\n\n\n" <<
	"Student GPA Calculator.\n\n" << "Enter five (5) alphabetical (ABCDF) " <<
	"grades for each student.\n" << flush; };

//the main
int main()
{
	const char *cStudentName [4]  = {"Freddie", "Jane", "Jonathan", "Mary"};
	float fGradeTotals [4] = {0.0f, 0.0f, 0.0f, 0.0f};
	int iCounter2;

	ProgramHeader(); //function call for the program header

	//the loop to fill the GradeTotals 
	for (int iCounter1 = 0; iCounter1 < 4; iCounter1++)
	{

		cout << "\nThe students name is " << cStudentName[iCounter1] << "\n" << flush;
		iCounter2 = 0;
		fGradeTotals[iCounter1] = fGetGrades(iCounter2++);
		cout << "*****" << fGradeTotals[iCounter1]<< endl << endl;

	}	//end for loop

	fOutputGPA(cStudentName, fGradeTotals);

	return 0;
}//end main



//recursive function to get the grades and fill the array
float fGetGrades(int iGradeCounter)
{
	char cGradeInput;

	if (iGradeCounter <= 5) //only gets 5 valid grades
	{
		cout << "Enter grade #" << (iGradeCounter + 1) << ": " << flush;
		cGradeInput = _getch();
		cout << cGradeInput << "\n" << flush;

		//the case to add up the grades
		switch (cGradeInput)
		{
		case 'A':
		case 'a':
			return fGetGrades(iGradeCounter + 1) + 4.0f;
			break;
		case 'B':
		case 'b':
			return fGetGrades(iGradeCounter + 1) + 3.0f;
			break;
		case 'C':
		case 'c':
			return fGetGrades(iGradeCounter + 1) + 2.0f;
			break;
		case 'D':
		case 'd':
			return fGetGrades(iGradeCounter + 1) + 1.0f;
			break;
		case 'F':
		case 'f':
			return fGetGrades(iGradeCounter + 1) + 0.0f;
			break;
		default:	//the catch all for error checking
			cout << "You must enter an A, B, C, D or F." << "\n" << flush;
			return fGetGrades(iGradeCounter); //calls the function with out changing counter
		}	//end switch
	}//end if
	else
	{
		return 0.0f;  //returns a 0.0 when it is called again and has 5 valid grades
	}//end else
}//end fGetGrades



//function for output
void fOutputGPA(const char *cNameStudent[], float fGPAs[])
{
	//the begining of the output
	cout << "\n\nThe following are the GPA's for each of the students. \n\n" <<
		setw(12) << setiosflags(ios::fixed | ios::left) << "Student"
		 << "GPA \n" << "--------    -----\n" << flush;

	//output for loop.  it's to go thru the arrays
	for (int iOutCounter = 0; iOutCounter < 4; iOutCounter++)
	{
		cout << setw(12) << setiosflags(ios::fixed | ios::left) << cNameStudent[iOutCounter] <<
			setiosflags(ios::fixed | ios::showpoint) <<
			setprecision (3) << fCalculateGPA(fGPAs[iOutCounter]) << "\n" << flush;
	}	//end of output for loop

	cout << "\nPress any key to continue..." << flush;
	_getch();
}
  

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

August 2014

S M T W T F S
     12
3456789
10111213141516
1718192021 22 23
24252627282930
31      

Tags

    Recent Entries

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories