大家好,請看看我的程序,並幫我找出它有什麼問題。它編譯並運行。該程序要求用戶輸入等級,輸入後將計算總預備等級,並顯示總等級的相應備註。但是,這是我的問題,相應的評論根本不顯示,它只顯示評論的無效輸入。請幫助我謝謝。聲明函數
#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";
}
'computePG'永遠不會分配'pScore',這是傳遞給'備註'的輸出變量。 (無論如何哪個指針不是真的。) – Rup
您是否嘗試過調試該程序?你知道,設置斷點和觀察變量值等... – dwo
'conio.h'是一個DOS頭(提供'getch')。它不可移植,您應該用'cin.get();'或'cin.ignore();'替換'getch();'。 – dyp