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

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.

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

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.

commented: Good explanation, thanks for not just giving the code to the OP +6

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.

Please post your current code with the changes you've made.

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

I meant more for you to show us what you tried with the passing by reference.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.