期望变量未声明和主要表达

时间:2016-08-01 16:11:07

标签: c++

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int amount;
    int newAmount;
    int interestRate;
    int initialAmount;

    cout << "Please enter the dollar amount. "; 
    cin >> amount;            
    cout << "Please enter the interest rate(e.g., nine percent shouold be entered as 9.0). ";
    cin >> interestRate;

    newAmount = FutureValue(amount,interestRate);

    cout << "The new dollar amount is ", newAmount;

    FutureValue(int initialAmount, int interestRate);
    int finalAmount;
    finalAmount = (1 + interestRate/100) * initialAmount;
    return finalAmount;

    system("PAUSE");
    return EXIT_SUCCESS;
}

我到了 “19`Re'sValue'未声明(首先使用此功能)” “23”在“int”之前预期的初级表达“ 并且“23”在“int”之前再次预期初级表达

2 个答案:

答案 0 :(得分:2)

我建议实际声明该函数,并从第23行删除“声明”。你不能声明这样的函数,即使你可以,你在声明它之前调用它会导致错误

FutureValue(int initialAmount, int interestRate) // Place whole thing before main
{
     int finalAmount;
     finalAmount = (1 + interestRate/100) * initialAmount;
     return finalAmount;
}

FutureValue(int initialAmount, int interestRate); // Before Main
// Later
FutureValue(int initialAmount, int interestRate) // Place after Main
{
     int finalAmount;
     finalAmount = (1 + interestRate/100) * initialAmount;
     return finalAmount;
}

答案 1 :(得分:0)

我认为从23上的方法调用中删除int将解决第二个问题。如果您的方法未申报,请确保您正确地将所有内容大写并使用正确数量的参数。