//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;
}
当它到达时它是否完成等式并开始输出它会全部混乱并被抛在一起。它是一个简单的利息计算器应用程序。
答案 0 :(得分:6)
我保证,如果您正在进行利率计算(或其他任何需要浮点精度的计算),您应该不使用int
数据类型。
此外^
不是权力运营商,它是独占运营商。您需要查看pow
标准库函数。
如果没有我为你完成所有的工作,你应该知道为什么你的家庭作业行为不端,这应该是足够的。
旁边:构造
cout<<"Interest Rate", cout<<R;
是一个非常罕见的。 可以工作(我不知道逗号操作符是否是序列点而且我现在懒得去查看它),但你应该更喜欢像平常一样的东西:
cout << "Interest Rate: " << R << endl;
你可能想在某个时候输出A
(答案): - )