1

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";
  }
3
  • 2
    computePG never assigns pScore, which is the output variable that's passed into Remark. (Which isn't really p for pointer anyway.) Commented Aug 23, 2013 at 10:51
  • 1
    Have you tried debugging the program? You know, settings breakpoints and watching variable values and the like... Commented Aug 23, 2013 at 10:51
  • conio.h is a DOS header (providing getch). It's non-portable and you should probably replace getch(); with cin.get(); or cin.ignore(); instead. Commented Aug 23, 2013 at 10:57

2 Answers 2

5

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;
  }
Sign up to request clarification or add additional context in comments.

1 Comment

You're right! I have forgotten that the variable that holds the total score is 'pScore' and not 'cpScore'. Thanks a lot :)
0

Variable double& pScore is not updated by function computePG.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.