代碼正在編譯和所有,但它不能正常工作。第一個if語句正常工作,但是它試圖測試其他函數時它沒有做它應該做的事情。它會將它添加到它正在顯示的值上。請,並提前感謝您的幫助。C++如果其他語句運行不正常
#include <iostream>
int main()
{
// b representing Balance, Fee is self-explanitory
int b = 0;
float fee = 0;
std::cout << "Enter the beginning balance of your bank account:" << std::endl;
std::cin >> b;
if (b < 400) {
fee = 25;
}
else {
fee = 10;
}
// if, else if statements for check fees
int c = 0;
std::cout << "Enter the amount of checks written this month" << std::endl;
std::cin >> c;
if (c < 20) {
float cf = 0.10;
cf *= c;
fee += cf;
std::cout << "Your bank fees for this month will be: $"
<< fee << std::endl;
return 0;
} else if (c = 20 && c <= 39) {
float cf = 0.08;
cf *= c;
fee += cf;
std::cout << "Your bank fees for this month will be: $"
<< fee << std::endl;
return 0;
} else if (c = 40 && c <= 59) {
float cf = 0.06;
cf *= c;
fee += cf;
std::cout << "Your bank fees for this month will be: $"
<< fee << std::endl;
return 0;
} else (c >= 60) ;{
float cf = 0.04;
cf *= c;
fee += cf;
std::cout << "Your bank fees for this month will be: $"
<< fee << std::endl;
return 0;
}
}
請一致縮進。 –
你正在測試的測試用例是什麼,你的預期結果是什麼,你的結果是什麼? – KRUKUSA
測試用例可以是以下輸入:B = 300 C = 25。結果應該是27,但它給出25.08。 –