-5

みんな、私のプログラムでもう一度助けてください。その中のコードの順序を変更しました。コードの何が問題なのかを確認してください。実行されますが、実行すべきタスクを実行しません。ユーザーが入力した成績の合計を計算し、対応するコメントを表示する必要があります。残念ながら、うまくいきません:(助けてください

#include<iostream>
#include<conio.h>

using namespace std;

void computePG(int& PG);
void Remark(int PG);

    int x, y, z, w, p;
    int prelimGrade,yourRemark,PG;
    int preliminaryGrade; 

int main()
{
    int pGrade;

 cout<<"Programmed by: Katrina G. Gozo, 1ISC";
 cout<<endl<<"\nDate: Aug. 23,2013";
 cout<<endl<<"\nThis program intends to compute the PG and make the necessary remarks";

 cout<<"\n\nPlease enter your score on quiz 1 ";
 cin>>x;

 cout<<"\nPlease enter your score on quiz 2 ";
 cin>>y;

 cout<<"\nPlease enter your score on quiz 3 ";
 cin>>z;

 cout<<"\nPlease enter your score on prelims ";
 cin>>p;


computePG(pGrade);
Remark(pGrade);


getch();
}

void computePG(int& PG)
{
    PG = x/30 * 20 + y/50 * 20 + z/40 * 20 + w/100 * 40;
    cout << "\nYour prelim grade is " << PG;

} 

void Remark(int PG)
{
     if (PG>=90)
        cout<<"A." <<endl;
     else if (PG>=80)
          cout<<"B."<<endl;
     else if (PG>=70)
          cout<<"C."<<endl;
     else if (PG>=60)
          cout<<"D."<<endl;
     else 
          cout<<"E."<<endl;
}
4

2 に答える 2

1

整数演算に違反している可能性が最も高いです。注: 整数を別の整数で割ると、整数の結果が得られます (ゼロに向かって丸められます)。

したがって、 と の型として使用しdouble、、などのように記述して、浮動小数点数の定数も作成する必要があります。PGpGradecomputePG30.020.0

于 2013-08-23T14:07:29.547 に答える
0

おそらく、変数「PG」に double を使用する必要があります。これにより、十分な小数精度が得られます。

また、将来的にはグローバル変数を避けたいと思うかもしれません。これは、このエラーをどのように作成したかを推測しているためです。w使用する前に値を割り当てることはありません。つまり、コンパイラによって値 0 が割り当てられ、あなたの結果を台無しにしています。

于 2013-08-23T14:14:02.590 に答える