我在编写控制台应用程序以创建一个简单的程序来解决养老金的数学方程时遇到问题
I'm having trouble writing a console application to create a simple program to solve a math equation for superannuation
谁能帮我一下?我已经绞尽脑汁一个多小时了,还是不能使它工作。这是在C++
,我已经学了一点,但我还是个新手…
int main()
{
double rate, amount,time, S;
cout << "Insert the time of the super: ";
cin >> time;
cout << "Insert the rate (as a decimal, eg 1% AKA 101% = 1.01): ";
cin >> rate;
cout << "Insert the amount $: ";
cin >> amount;
S =("amount * (rate ^ time - 1)", pow(rate,time));
cin >> S;
cout << "The total amount is: " << "S /(rate - 1)" << endl;
system("PAUSE");
return 0;
}
我没有得到一个编译错误,但我永远不能得到答案,从它
你"永远得不到结果"因为你用逗号操作符将S设置为pow
的结果然后用
cin >> S;
正在等待您输入另一个数字。
你有两个主要问题。以下是更新后的代码,并对更改的部分进行了注释:
int main()
{
double rate, amount,time, S;
cout << "Insert the time of the super: ";
cin >> time;
cout << "Insert the rate (as a decimal, eg 1% AKA 101% = 1.01): ";
cin >> rate;
cout << "Insert the amount $: ";
cin >> amount;
S = amount * pow(rate, time - 1); // take away the quotes and don't make pow seperate
cout << "The total amount is: " << (S /(rate - 1)) << endl; // do the calculation and output it
system("PAUSE");
return 0;
}
请记住,引号"like this"
内的内容是字符串字面量,因此"4 * 4"
是字符串,但4 * 4
(请参阅没有引号)进行乘法运算,产生数字16
。
我认为你不应该像现在这样给S赋值。S被声明为双精度,你一开始给它赋值一个字符串。当您输出结果时,还将计算结果括在引号中。你应该简单地计算<<S/(速率-1);//不带引号或cout将直接输出字符串
相关文章:
- 最大的回文产品 - 程序未运行,编写解决方案但无法理解问题
- 如何解决在负数的情况下程序以相同方式工作的问题?
- 系统错误:程序无法启动,因为您的计算机中缺少MSVCP140D.DLL。尝试重新安装该程序以解决此问题
- 如何在Arduino程序中解决"invalid operands of types"?
- 在Linux/Ubuntu中编译openCV应用程序时,如何解决未定义的引用cv:..?
- 试图解决这个简单的C++程序,但我被困在某个地方
- 如何在程序中实现单词跳过解决方案
- 如何在不设置 ulimit -n 的情况下解决套接字程序打开太多文件的错误
- 在跨平台桌面/移动应用程序套件中使用 ZeroMQ 来解决架构问题
- 开发如何解决错误193:%1不是Dev C 中的Win32应用程序
- 当我们在以下程序(C )中输入字符时,该如何解决
- 如何计算该程序的复杂性?是否有任何其他复杂性较低的解决方案
- 我收到阻止我运行程序的警告,但不确定如何解决
- QT创建者:简单程序未解决的外部符号和外部符号错误
- 如何解决使用QXml格式化程序时FODC0002的错误
- 任何熟悉Codecademy C++/程序的人都可以帮助解决菜鸟问题吗?
- MPI在某个进程找到解决方案时使用广播结束程序
- 谁能帮助我解决以下 c++ 代码中的问题?该程序不提供任何输出
- 如何将解决方案中的项目从应用程序更改为静态库
- 如何在QT Android应用程序中解决慢速滚动