嘿家伙我有一个我无法检测到的错误。请帮助我。在这段代码我想计算百分比,但在计算之后有一个零值存储在变量“百分比”显示零值的变量百分比
int _tmain(int argc, _TCHAR* argv[])
{
int total_marks, obtained_marks, percentage;
total_marks = 1100;
cout << "enters yours obtained marks"<<endl;
cin >> obtained_marks;
percentage = (obtained_marks/total_marks) * 100;
cout << "yours percentage =" << percentage;
if (percentage >= 60)
{
cout << "you have passed with first division";
}
cout << "yours pecentage is=" << percentage;
system("pause");
return 0;
}
为什么你使用'int'? – user463035818
因为所有的变量都包含没有小数的数字,所以我也用百分比变量的浮点数,但仍然给零值。 –
如果用户输入例如100,那么100/1100有小数位 – user463035818