// 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;
}
ok at line“answer = playerinput *(1 + intrates)^ years;”我在playerinput下面得到一条红线,它说指向函数somthing ....我不明白yi得到了这个错误,我的任务是“编写一个程序来计算你最终会得到多少钱你投资了 按固定利率计算的金额,每年复合。“我充满信心的方程式是正确的,当我运行已完成的程序时,它将运行它应该的方式,如果我在方程式中错了,可以随意离开饲料谢谢你
答案 0 :(得分:2)
小帽子(^)在C ++中不是取幂,我想你的意思是:
answer = pow( playerinput * (1 + intrates), years );
将“playerinput *(1 + intrates)”提升到权力“年”。</ p>
哦,FYI ^ = XOR,按位是。
答案 1 :(得分:1)
^
不是它的按位xor所以你应该使用pow而不是
#include <math.h>
[...]
answer = playerinput * pow ((1 + intrates), years);
[...]