注册 登录
编程论坛 C++教室

error: expected ')'

memepapa 发布于 2021-12-28 11:08, 1603 次点击
这是我在网上找到的一个 C++ 计算 compound interest 的代码,应该是比较旧版的,所以我 compile 时出现了以下错误


error: expected ')'
    while (choice! = -99)
                 ^
note: to match this '('
    while (choice! = -99)


请问谁能指导我怎么处理修改吗?

下面是完成的代码




#include <iostream>

#include <stdlib.h>

#include <cmath>

using namespace std;

double simple_interest (double principal, double rate, double time);

double compound_interest (double principal, double rate, double time);

double compound_interest_ear (double principal, double rate, double time, double period);

int main ()
{

    double amount, principal, rate, time, interest, R;

    int choice;

    double SI, CI, EAR, Amount, period;

    amount = principal = rate = time = interest = 0.0;

    while (choice! = -99)
    {

        cout << "\n\n\n\n\n";

        cout << "\t\t\tEnter Principal amount:"; cin >> principal;

        cout << "\t\t\tEnter Rate (In percentage):"; cin >> R;

        rate = R/100;

        cout << "\t\t\tEnter Time (In Years):"; cin >> time;

        cout << "\t\t\t" << principal << endl;

        cout << "\t\t\t" << rate << endl;

        cout << "\t\t\t" << time << endl;

        cout << "\t\t\t************ MENU ********************" << endl;

        cout << "\t\t\t1: Simple Interest" << endl;

        cout << "\t\t\t2: Compound Interest" << endl;

        cout << "\t\t\t3: Effective Annual Rate (Compound Interest)" << endl;

        cout << "\t\t\t****************************************" << endl;

        cout << "\t\t\tEnter You Choice:"; cin >> choice;

        if(choice == 3)
        {

            cout << "\t\t\tNo of Period in a Year:";
            cin >> period;

        }

    switch(choice)
    {

        case 1:

            SI = simple_interest (principal, rate, time);

            Amount = principal + SI;

            cout << "\n\n\n";

            cout << "\t\t\tSimple Interest =" << " "<< SI << endl;

            cout << "\t\t\tTotal Amount =" << " " << Amount<< endl;

            break;

        case 2:

            Amount = compound_interest(principal, rate, time);

            CI = Amount - principal;

            cout << "\n\n\n";

            cout << "\t\t\tCompound Interest with Principal =" << " "
            <<
            Amount << endl;

            cout << "\t\t\tTotal Compound Interest ="<< " " <<
            CI << endl;

            break;

        case 3:

            Amount = compound_interest_ear(principal, rate, time, period);

            CI = Amount - principal;

            EAR = pow((1 + (rate/period)),period)-1;

            cout << "\n\n\n";

            cout << "\t\t\tCompound Interest with Principal =" << " " <<
            Amount << endl;

            cout << "\t\t\tTotal Compound Interest =" << " " <<
            CI << endl;

            cout << "\t\t\tEffective Annual Rate =" << " " <<
            EAR << endl;

            cout << "\t\t\tNomianal Rate =" << " " <<
            rate << endl;

            break;

        default:

            cout << "\t\t\tSorry ! Try again";

            break;

        }

    cout << "\n\n\n";

    cout << "\t\t\tDo you want to Continue?" << endl;

    cout << "\t\t\tEnter -99 to end" << endl;

    cout << "\t\t\tOr Enter any other number to Continue:";
    cin << choice;

    }

    system("PAUSE");

    return EXIT_SUCCESS;

}

// Simple interest

double simple_interest(double principal, double rate, double time)
{

    double SI = principal * rate * time;

    double Amount = principal + SI;

    return SI;

}

// Compound Interest

double compound_interest(double principal, double rate, double time)
{

    double CI;

    double Amount;

    Amount = principal * pow((1 + rate),time);

    return Amount;

}

// Compound Interest with the effective annual rate

double compound_interest_ear(double principal,double rate, double time,double period)
{

    double CI, EAR, Amount;

    period = period * time;

    Amount = principal * pow((1 + (rate/period)),period);

    return Amount;

}


2 回复
#2
rjsp2021-12-28 13:27
while (choice! = -99)
改为
while (choice != -99)

cin << choice;
改为
cin >> choice;

int choice;
改为
int choice = 0;
#3
memepapa2021-12-28 18:37
回复 2楼 rjsp
谢谢指导,感激
1