C++ 我想做一个期末成绩计算器,但它不是';行不通
这里是C++初学者。 所以,我试图让这段代码像期末成绩计算器一样工作,但它不起作用。它每次返回100的值。怎么了C++ 我想做一个期末成绩计算器,但它不是';行不通,c++,C++,这里是C++初学者。 所以,我试图让这段代码像期末成绩计算器一样工作,但它不起作用。它每次返回100的值。怎么了 #include <iostream> using namespace std; int main() { double grade, des, worth, per, grade1, tgrade, fgrade; cout<<"What is your current grade in the class?"<<endl;
#include <iostream>
using namespace std;
int main()
{
double grade, des, worth, per, grade1, tgrade, fgrade;
cout<<"What is your current grade in the class?"<<endl;
cin>>grade;
cout<<"What is your desired grade in the class?"<<endl;
cin>>des;
cout<<"How much is your final exam worth? (Percent of total grade)"<<endl;
cin>>worth;
per=1-(worth/100);
grade1=grade*per;
fgrade=100;
while ((tgrade-0.01)<=des<=(tgrade+0.01)) {
fgrade=fgrade-1;
tgrade=grade1+(fgrade*(worth/100));
}
cout<<"You need a grade of "<<fgrade<<"% on your final exam to reach your desired grade in your class. Good Luck!"<<endl;
return 0;
}
#包括
使用名称空间std;
int main()
{
双年级,des,worth,per,1年级,tgrade,fgrade;
cout我可以看到您试图在循环条件中实现的逻辑,但是另外,tgrade
在使用之前从未初始化过,因此循环无论如何都会出现错误。我按照您所说的做了,但在尝试时它仍然返回值100。另外,@JoachimIsaksson您建议我如何初始化它?这是否回答了您的问题在1级上的仅分配给,而per
仅用于计算。