声明功能

Ang*_*oya 1 c++

大家好,请看看我的程序并帮我找出它的错误.它编译并运行.程序要求用户输入成绩,输入后,它将计算总预备等级,并应显示总成绩的相应备注.但这是我的问题,相应的注释根本不显示,它只显示备注的无效输入.请帮我谢谢.

#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";
  }
Run Code Online (Sandbox Code Playgroud)

Nem*_*ric 5

pScore作为参考传递,但您没有为其分配任何值,而是将结果存储到本地变量中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;
  }
Run Code Online (Sandbox Code Playgroud)