方程在C++中无法正常工作

Sam*_*nna -2 c++

//Samuel LaManna
//Program 1 (intrest rate)
/*Variables:
Principal=P
Interest Rate=R
Times Compounded=T
Answer=A */

#include <iostream>                                                                        //Input/output

using namespace std;

int main ()
{
  int P, R, T, A;                                                                          //Declaring Variables
  cout<<endl;
  cout<<"Interest Earned Calculator";                                                      //Prints program title
  cout<<endl;
  cout<<endl;
  cout<<"Please enter the Principal Value: ";
  cin >> P;
  cout<<endl;
  cout<<endl;
  cout<<"Please enter the Interest Rate (in decimal form): ";
  cin >> R;
  cout<<endl;
  cout<<endl;
  cout<<"Please enter the Number of times the interest is compounded in a year: ";
  cin >> T;
  cout<<endl;
  cout<<endl;
  A=P*((1+R)/T)^T;
  cout<<"Interest Rate", cout<<R;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

当它到达它是否完成方程式并开始输出时,它将全部混乱并抛出在一起.它是一个简单的利息计算器应用

pax*_*blo 6

我保证,如果您正在进行利率计算(或任何其他需要浮点精度的计算),您应该使用int数据类型.

此外^,不是电力运营商,它是独家或运营商.您需要查看pow标准库函数.

这应该足以让你弄清楚为什么你的家庭作业行为不端,没有我为你做所有的工作.

旁白:这个结构

cout<<"Interest Rate", cout<<R;

非常罕见.它可能会起作用(我不知道我的脑袋是否是一个序列点而且我现在懒得去查看它),但你应该更喜欢像平常一样的东西:

cout << "Interest Rate: " << R << endl;

你可能想A在某个时候输出(答案):-)