c++ - Visual C++ 错误 C2143 不知道缺少什么

标签 c++ visual-c++

错误 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/

相关文章:

c++ - 在光线追踪中对球体进行荒谬的反射

c++ - 如何将元素插入 vector 的开头?

c++ - 在继承自抽象类的模板类中正确使用未定义类型

c++ - Crypto API RSA 公钥可以解密数据,不是预期的不对称

c++ - 试图了解如何选择重载函数

c++ - MS 对 C++ 的扩展的有用性

c++ - 使用 std::hex 将十六进制转换为十进制

c - 是否可以检查您是否正在使用 Microsoft C 编译器构建 64 位?

c++ - 带有类对象的 iomanip

c++ - 是否有 Perl 脚本来实现 C++ Class get/set 成员函数?