【发布时间】:2013-12-09 04:43:46
【问题描述】:
if (Mileage > 0) do
{
calculateMileage();
cout << "The cost of shipment over " << setprecision(2) << Mileage << " miles is \234" << variableShippingCost << ".";
cout << "\n \n";
system("pause"); //to hold the output screen
return(0);
}
else
{
cout << "\n ERROR: The distance should be a positive value.";
system("pause"); //to hold the output screen
return(0);
}
我不知道为什么,但 Visual Studio 12 会在 else 上出现错误,说它需要一段时间。我之前做过很多 if else 语句,并且在这个程序中运行良好,所以任何人都可以帮助我理解为什么在这种情况下它不开心吗?
【问题讨论】:
-
谁教你这样使用
do? -
这是因为第一行末尾的
do。要么删除它,要么添加while以配合它。 -
天哪,我现在感觉自己像个白痴!感谢您指出这一点!
-
追加0x499602D2的问题:谁教你写
if(cond) do、return(0)和system("pause")?
标签: c++ if-statement while-loop