-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

您很可能与整数算术发生冲突。注意:将一个整数除以另一个整数时,会得到一个整数结果(向零舍入)。

因此,您将希望用作anddouble的类型,并将常量也设为浮点数,方法是将它们写为,等。PGpGradecomputePG30.020.0

于 2013-08-23T14:07:29.547 回答
0

您可能应该为变量“PG”使用双精度数,这样您将获得足够的小数精度。

另外,您将来可能希望避免使用全局变量,因为我猜这就是您犯此错误的方式-您w在使用它之前从未为其赋值,这意味着编译器将其赋值为 0 并且可能是什么搞砸了你的结果。

于 2013-08-23T14:14:02.590 回答