我想在for循環中添加兩個浮點數,並且它告訴我'+'沒有影響。我試圖使它通過兩個範圍的每個incrememnt口(.25)(begrate和endrate)(1和2),1 + 0.25工作不正常解析,我得到一個無限循環加法運算符沒有影響
float begrate,endrate,inc,year=0;
cout << "Monthly Payment Factors used in Compute Monthly Payments!" << endl;
cout << "Enter Interest Rate Range and Increment" << endl;
cout << "Enter the Beginning of the Interest Range: ";
cin >> begrate;
cout << "Enter the Ending of the Interest Range: ";
cin >> endrate;
cout << "Enter the Increment of the Interest Range: ";
cin >> inc;
cout << "Enter the Year Range in Years: ";
cin >> year;
cout << endl;
for (float i=1;i<year;i++){
cout << "Year: " << " ";
for(begrate;begrate<endrate;begrate+inc){
cout << "Test " << begrate << endl;
}
}
system("pause");
return 0;
'A + B'不修改'了'(或'B')。這是合乎邏輯的。有一組複合賦值操作符會影響'a'。 – chris
您可能想使用begrate + = inc而不是begrate + inc – drescherjm
也是您真的想要一年成爲一個浮動嗎?如果有人輸入1.5,則使用此計算不會得到所需的答案。 – drescherjm