Calc or Print returning '0.0'

I am less than a beginner in c++ and am taking a college course, an online course at that. The teacher is knowledgeable about c++, but I don't think he is so great at teaching it, or maybe I am just bad at learning it. He gave us some code and we were supposed to come up with the rest to write a win32 console program using visual studio 2008. The program is supposed to take the points a student received on a test, the points possible, and calculate the percentage or score. Here is the code I have, but it is always returning 0.0.

#include <iostream>
using namespace std;

double CalcPercentage(double pointsEarned, double pointsPossible);
void PrintPercentage(double scorePercent);
void ReadTestInfo(double &pointsEarned, double &pointsPossible);

void main()
{
double earned = 0.0;
double possible = 0.0;
double percent = 0.0;

ReadTestInfo(earned, possible); //Enter code to call the function ReadTestInfo

CalcPercentage(earned, possible); //Enter code to call the function CalcPercentage

PrintPercentage(percent);//Enter code to call the function PrintPercentage
}

double CalcPercentage(double pointsEarned, double pointsPossible)
{
double percent = pointsEarned / pointsPossible * 100.0; // Calculate Percentage store in the local percent variable

return (percent);
}

void ReadTestInfo(double &pointsEarned, double &pointsPossible)
{
cout << "Enter test score" << endl;//Request (Prompt) a test score from the user.

cin >> pointsEarned;//Store the value in pointsEarned

cout << "Enter max test score" << endl;//Request (Prompt) the maximum test score from the user.

cin >> pointsPossible;//Store the value in pointsPossible.
}

void PrintPercentage(double scorePercent)
{
cout << "The student's score is ";
cout.setf(ios::fixed);
cout.precision(2);
cout << scorePercent;

// Show the grade percentage stored in the scorePercent
}
You don't take the result form 'CalcPercentage()'. Like so:

1
2
3
4
5
6
7
8
9
10
11
12
void main()
{
double earned = 0.0;
double possible = 0.0;
double percent = 0.0;

ReadTestInfo(earned, possible); //Enter code to call the function ReadTestInfo

percent = CalcPercentage(earned, possible); //Enter code to call the function CalcPercentage

PrintPercentage(percent);//Enter code to call the function PrintPercentage
}


And use [code]Your code[/code]
Also don't use void main(). That isn't valid C++.
Topic archived. No new replies allowed.