For some odd reason, I can't get anything to be displayed when the program is running. I believe its not passing anything at all which would explain the blank console. If anyone could help me out that would be great.

Without using functions the program successfully shows:
1) Student's name
2) Current Grade
3) Overall grade
4) Inputs are successfully entered
5) Outputs are correctly displayed

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

//Prototypes being used:
void userData(string, int, char);
double calData(int, int, int);
void displayData(string, char, double);

//Variables

string studentName;
char letterGrade;
int numOfClasses, qp, totalPoints;
double gpa;

int main()
{
	//called functions
	void userData(string studentName, int numOfClasses, char letterGrade);
	double calData(int totalPoints, int numOfClasses);
	void displayData(string studentName,char letterGrade, double gpa);
	getch();
	return 0;
}


void userData(string studentName, int numOfClasses, char letterGrade)
{
	do
	{
		cout << "Enter the student's name: ";
		cin >> studentName;
		
		cout << "Enter number of classes taken: ";
		cin >> numOfClasses;
		if (numOfClasses > 3)
			cout << "ERROR: Only 3 Classes per term!" << endl;

	}while (numOfClasses>3);
	for (int i=1; i <numOfClasses; i++)
	{
		cout << "Enter the letter grade for class #" << i << ": ";
		cin >> letterGrade;

		if (letterGrade == 'A')
			qp = 4;
		else if (letterGrade == 'B')
			qp = 3;
		else if (letterGrade == 'C')
			qp = 2;
		else if (letterGrade == 'D')
			qp = 1;
		else 
			qp = 0;

		totalPoints += qp;
	}

}

double calData(int totalPoints, int numOfClasses)
{
	gpa = totalPoints/numOfClasses;
	return gpa;
}

void displayData(string studentName, char letterGrade, double gpa)
{
	cout << endl << " STUDENT NAME: " << studentName;
	cout << endl << " OVERALL GRADE: " << letterGrade;
	cout << endl << " CURRENT GPA: " << gpa << endl;
}

Edited 5 Years Ago by DaniwebOS: n/a

The first thing I see is this :

int main()
{
	//called functions
	void userData(string studentName, int numOfClasses, char letterGrade);
	double calData(int totalPoints, int numOfClasses);
	void displayData(string studentName,char letterGrade, double gpa);
	getch();
	return 0;
}

which is wrong and should be this :

int main()
{
	//called functions
	userData(studentName, numOfClasses, letterGrade);
	calData(totalPoints, numOfClasses);
	displayData(studentName,letterGrade, gpa);
	getch();
	return 0;
}

There are definitely other problems but that should get you started.

Edited 5 Years Ago by firstPerson: n/a

You don't need to have the data type when calling your function in the main() function.

int main()
{
	//called functions
	userData(string studentName, int numOfClasses, char letterGrade);
	calData(int totalPoints, int numOfClasses);
	displayData(string studentName,char letterGrade, double gpa);
	getch();
	return 0;
}

You also need to initialize totalPoints to zero prior to calling it for the first time. You can debug the code with break lines and then check what your local variables equate to line by line.

only error i am now getting would be > error C2660: 'calData' : function does not take 2 arguments

Any news why?

Check out line 8 of your original posting, your prototype says that it takes 3 arguments. Something must be changed so the number of parameters matches up in your prototype (line 8), your definition(line 63), and your function call (line 22).

//Prototypes being used:

void userData(string, int, char);

double calData(int, int, int);

void displayData(string, char, double);


// You need to change your function declaration of calData to two arguments, not three

Edited 5 Years Ago by Saith: n/a

Thanks for the tremendous help guys, the only problem that I am now getting so far would be the numOfClasses not passing at all. The debugger says the totalPoints is 7 for A/B but the numOfClasses is shown as 0 when I actually choose 3.

Okay. I just compiled your code and debugged a bit. The reason why are getting an error when running your code is due to the divide by zero effect. It's GG.

You are wondering why numOfClasses = 0 by the time you call the second function, it's because numOfClasses actually equals zero.

Why? Because in the first function, you passed the value argument, pass-by-value, and not pass-by-reference. You told the function that numOfClasses equals 3 through cin, but that assignment to numOfClasses was only valid in that functions block of code. Once the block ends, numOfClasses value is now wiped and replaced by the value prior to the function call, zero. Making all the parameters for that first function, pass-by-reference, you will save those variables past the end of the block from the function. You will also need those variables saved past that first block to be used in the third function.

Also, in your third function, the output function to the screen with the final results. There are no syntax errors, but there are logical errors. Your output of letter grade outputs the LAST LETTER GRADE entered. NOT the average letter grade. So if you inputted A, A, C. Your letter grade is C, which should be B.

Also, for -just in case-, you want to equate totalPoint to zero prior to using totalPoints += qp; as it also means, totalPoints = totalPoints + qp; and if there is some random junk from a previous program, your total points will be way off.

Finally, it's best to put variables in local blocks instead of globally. It overall a better technique.

Edited 5 Years Ago by Saith: n/a

Comments
Good explanation, thanks for not just giving the code to the OP

So when I try to change the arguments to pass by reference I get a ton of errors that says
c2275 'std::string': illegal use of this type as an expression and many other errors.

So this is the current code, everything works except for the student name and overall grade not passing at all...

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

//Prototypes being used:
void userData(string, int, char);
double calData(int, int);
void displayData(string, char, double);

//Variables

string studentName;
char letterGrade;
int numOfClasses=3, qp, totalPoints;
double gpa;

int main()
{
	//called functions
	totalPoints = 0;
	userData(studentName, numOfClasses, letterGrade);
	calData(totalPoints, numOfClasses);
	displayData(studentName, letterGrade, gpa);
	getch();
	return 0;
}


void userData(string studentName, int numOfClasses, char letterGrade)
{
	do
	{
		cout << "Enter the student's name: ";
		cin >> studentName;
		
		cout << "Enter number of classes taken: ";
		cin >> numOfClasses;
		if (numOfClasses > 3)
			cout << "ERROR: Only 3 Classes per term!" << endl;

	}while (numOfClasses>3);
	for (int i=1; i <=numOfClasses; i++)
	{
		cout << "Enter the letter grade for class #" << i << ": ";
		cin >> letterGrade;

		if (letterGrade == 'A')
			qp = 4;
		else if (letterGrade == 'B')
			qp = 3;
		else if (letterGrade == 'C')
			qp = 2;
		else if (letterGrade == 'D')
			qp = 1;
		else 
			qp = 0;

		totalPoints += qp;
	}

}

double calData(int totalPoints, int numOfClasses)
{
	gpa = totalPoints/numOfClasses;
	return gpa;
}

void displayData(string studentName, char letterGrade, double gpa)
{
	cout << endl << " STUDENT NAME: " << studentName;
	cout << endl << " OVERALL GRADE: " << letterGrade;
	cout << endl << " CURRENT GPA: " << gpa << endl;
}

Thanks for the tremendous help everyone, you guys led me to the right direction and educated me with a lot of stuff I had not realized.


Issue resolved!

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