错误 C2143:语法错误:缺少“;”在“常量”之前
我不知道发生了什么。我像往常一样写作,这是我第一次遇到这个错误。我仍然是新手,正在学习,所以我可能会错过一些明显的东西,但我不知道这意味着什么,该程序对我来说看起来是正确的。我在哪里缺少分号?这也是我唯一的错误。
double LoanA, Interest, monthlyP, balance, totalInterest, monthlyI, LastPay;
int monthCount;
cout << "Enter the loan ammount: $";
cin >> LoanA;
cout << endl << "Enter annual interest rate in percentage: ";
cin >> Interest;
cout << endl << "Enter monthly payment: $";
cin >> monthlyP;
cout << endl;
monthCount = 1;
balance = LoanA;
totalInterest = 0;
monthlyI = 0;
Interest = Interest/100;
while (balance > 0)
{
monthlyI = (balance*Interest)12;
balance = balance + monthlyI;
balance = balance - monthlyP;
totalInterest = totalInterest + monthlyI;
monthCount++;
cout << "month: " << monthCount << " Interest paid: " << monthlyI << " Remaining debt: " << balance << endl;
}
LastPay = (balance+monthlyP)+monthlyI;
cout << "Total number of payments = " << monthCount << endl;
cout << "Total amount of interest paid = " << totalInterest << endl;
cout << "The last payment = " << LastPay << endl;
最佳答案
这一行语法无效
monthlyI = (balance*Interest)12;
// ^^^
你的意思可能是:
monthlyI = (balance*Interest) / 12;
// ^^^^
关于c++ - Visual C++ 错误 C2143 不知道缺少什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19536889/