Reputation: 75
Hello guys kindly take a look at my program and help me find what's wrong with it. It compiles and also runs. The program asks the user to enter grades, after inputting, it will compute the total prelim grade and it should display the corresponding remark of the total grade. But that's my problem, the corresponding remark doesn't display at all, it just displays invalid input for the remark. Please help me thanks.
#include<iostream>
#include<conio.h>
using namespace std;
void computePG(double& pScore);
void Remark(double pScore);
int main()
{
double cPrelimGrade;
cout << "\n\n\tThis program is intended to compute the prelim grade\n";
computePG(cPrelimGrade);
Remark(cPrelimGrade);
getch();
}
void computePG(double& pScore)
{
double q1, q2, q3, pe, cpScore = 0;
cout << "\n\n\tPlease enter your score in quiz 1: ";
cin >> q1;
cout << "\tPlease enter your score in quiz 2: ";
cin >> q2;
cout << "\tPlease enter your score in quiz 3: ";
cin >> q3;
cout << "\tPlease enter your score in prelim exam: ";
cin >> pe;
cpScore = ((q1/30) * 20) + ((q2/50) * 20) + ((q3/40) * 20) + ((pe/100) * 40);
cout << "\n\n\tThe computed PG is: " << cpScore;
}
void Remark(double pScore)
{
if (pScore<=59&&pScore>=0)
cout << "\n\tRemark: E";
else if (pScore<=69&&pScore>=60)
cout << "\n\tRemark: D";
else if (pScore<=79&&pScore>=70)
cout << "\n\tRemark: C";
else if (pScore<=89&&pScore>=80)
cout << "\n\tRemark: B";
else if (pScore<=100&&pScore>=90)
cout << "\n\tRemark: A";
else
cout << "\n\t\tInvalid input";
}
Upvotes: 1
Views: 175
Reputation: 22187
You are passing pScore
as a reference, but you are not assigning any value to it, instead you are storing your result into local variable cpScore
:
void computePG(double& pScore)
{
double q1, q2, q3, pe, cpScore = 0;
cout << "\n\n\tPlease enter your score in quiz 1: ";
cin >> q1;
cout << "\tPlease enter your score in quiz 2: ";
cin >> q2;
cout << "\tPlease enter your score in quiz 3: ";
cin >> q3;
cout << "\tPlease enter your score in prelim exam: ";
cin >> pe;
pScore = ((q1/30) * 20) + ((q2/50) * 20) + ((q3/40) * 20) + ((pe/100) * 40);
cout << "\n\n\tThe computed PG is: " << pScore;
}
Upvotes: 5