C++ I';我很难编写控制台应用程序来创建一个简单的程序来解决退休金的数学方程

C++ I';我很难编写控制台应用程序来创建一个简单的程序来解决退休金的数学方程,c++,C++,谁能帮我一下吗? 我绞尽脑汁想了一个多小时,没法把它用上。 这是在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): ";

谁能帮我一下吗? 我绞尽脑汁想了一个多小时,没法把它用上。 这是在
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;
}
intmain()
{
双倍费率、金额、时间、秒;
时间;
速率;
数量;
S=(“金额*(费率、时间-1)”,功率(费率、时间));
cin>>S;
cout您“永远不会得到结果”,因为您使用逗号运算符weirdness将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;
}
intmain()
{
双倍费率、金额、时间、秒;
时间;
速率;
数量;
S=amount*pow(rate,time-1);//去掉引号,不要将pow分开
cout您“永远不会得到结果”,因为您使用逗号运算符weirdness将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;
}
intmain()
{
双倍费率、金额、时间、秒;
时间;
速率;
数量;
S=amount*pow(rate,time-1);//去掉引号,不要将pow分开

cout我认为你不应该按你现在的方式给S赋值。S被声明为double,你在开始时给它赋值。当你输出结果时,你也在用引号括起计算。你应该简单地说cout我认为你不应该按你现在的方式给S赋值。S被声明为doubl一开始,你是在给它赋值。当你输出结果时,你也在把计算结果括在引号里。你应该简单地认为-1应该被分组为pow(rate,time-1)而不是pow(rate,time)我可能错了。@template是的,我想你是对的,看起来是这样的,我错了。我认为-1应该被归为pow(速率,时间-1)而不是pow(速率,时间)-1.不过我可能错了。@template是的,我想你是对的,看起来是这样的,我错了。他没有给它赋值字符串,而是给它赋值一个double,因为
pow
返回一个double,逗号操作符“discards”第一个表达式。他没有给它赋值字符串,而是给它赋值了一个double,因为
pow
返回一个double,逗号运算符“丢弃”第一个表达式。