2012-12-03 32 views
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; 
} 

確定在行「answer = playerinput *(1 + intrates)^ years;」我在playerinput下面看到一條紅線,它說的是指向函數的東西......我不明白yi得到那個錯誤,我的任務也是「編寫一個程序,計算你最終會得到多少錢if你以固定利率投資 金額,每年複利。「我有足夠的自信的方程式是正確的,當我運行完成的程序時,它將運行它應該的方式,如果我在方程中有錯誤,請隨時留下反饋。謝謝(pointer-to)error .... *嘆息*

回答

2

小帽子(^)在C++中不冪,我想你的意思是:

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

這將提高 「playerinput *(1個+ intrates)」 的力量 「年」。

哦,FYI = =異或,即按位。

+0

非常感謝現在努力吧....河畔感謝響應速度非常快,我在訓練小白:) –

+0

'pow(playerinput *(1 + intrates),years);'與'playerinput * pow((1 + intrates),年)不一樣;' – phschoen

+0

這是真的,但我保留了原來的邏輯。它會首先乘以「playerinput *(1 + intrates)」 - 無論是因爲優先還是從左到右,請選擇 - 然後進行冪運算。假設'^'是指數運算符。我無法知道他想要計算什麼,只是他不明白爲什麼異或操作員給他一個錯誤。 –

1

^不是戰俘的按位異或,所以你應該使用POW代替

#include <math.h> 
[...] 
answer = playerinput * pow ((1 + intrates), years); 
[...] 
+1

感謝這一個工作對方給了我我的延遲號碼,但這給了我正確的一個非常感謝:) –

+0

因此,如果其正確的一個按複選標記 – phschoen