1
// program assignment 2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "math.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    double percentconverter;
    int playerinput;
    int years;
    double intrates;
    double answer;

    cout << " Enter initial amount:" << endl;
    cin  >> playerinput;

    cout << "Enter number of years:" << endl;
    cin  >> years;

    cout << "Enter interest rate (percent per year):" << endl;
    cin  >> percentconverter;

    intrates = percentconverter / 100;
answer = playerinput * (1 + intrates) ^ years;

    return 0;
}

「答え=プレイヤー入力*(1 +イントラテス)^年;」行でOK プレーヤー入力の下に小さな赤い線が表示されます。関数へのポインターの何かが表示されます....そのエラーが表示されることを理解できません。また、「もし一定額の金額を年複利の固定金利で投資します。」私が確信している方程式は正しいと確信しており、完成したプログラムを実行すると、本来の方法で実行されます。方程式が間違っている場合は、遠慮なくフィードバックを残してください。ありがとうございました

4

2 に答える 2

2

小さな帽子 (^) は C++ の累乗ではありません。

answer = pow( playerinput * (1 + intrates), years );

これは、「playerinput * (1 + intrates)」を「年」で累乗します。

ああ、FYI ^ = XOR、つまりビット単位です。

于 2012-12-03T21:17:39.710 に答える
1

^ビットごとの xor は pow ではないため、代わりに pow を使用する必要があります

#include <math.h>
[...]
answer = playerinput * pow ((1 + intrates), years);
[...]
于 2012-12-03T21:21:56.890 に答える