通胀率计算器c ++

时间:2016-09-22 01:41:23

标签: c++

我正在尝试建立通胀率计算器,但它不起作用。 我现在已经离开这个国家并且使用学校的PC所以所有的错误都出现在韩语中,我已经翻译了它们但却不太了解它们。

#include <iostream>
using namespace std;

double inflationRate (double startingPrice, double currentPrice);

int main()
{
    double startingPrice, currentPrice;
    char again;

    do 
    {
        cout << "enter the price of the item when you bought it: ";
        cin >> startingPrice;

        cout << "enter the price of the item today: ";
        cin >> currentPrice;

        cout << "the inflation Rate is: " << inflationRate(startingPrice, currentPrice) << "%";

        cout << "would you like to try another item (y/n)?";
        cin >> again;

    }while((again == 'Y') || (again =='y'));

    return 0;
}

double inflationRate(double startingPrice, double currentPrice)
{
    return ((currentPrice - startingPrice) / startingPrice);
}

1&GT; ------ Build build:项目:测试,配置:调试Win32 ------

1&GT;建立开始时间:2016-09-22 11:04:39 AM

1&GT; InitializeBuildStatus:

1&GT; “Debug \ testing.unsuccessfulbuild”连接(触摸)a。

1&GT; ClCompile:

1&GT;所有输出都是最新的。

1&GT; ManifestResourceCompile:

1&GT;所有输出都是最新的。

1&GT; LINK:致命错误LNK1123:转换为COFF期间发生错误。或者损坏的文件不正确。

1&GT;

1&GT;未能建立。

1&GT;

1&GT;经过时间:00:00:00.08

==========构建:0成功,1失败,最新0,0跳过==========

1 个答案:

答案 0 :(得分:0)

您正在声明无用的变量inflationRate,而不是调用函数inflationRate。我认为这就是你想要的(我假设第一行缺少#是复制粘贴错误):

#include <iostream>
using namespace std;


double inflationRate (double startingPrice, double currentPrice);  // <-- Missing semicolon!


int main() // <-- Not void; use int.
{
double startingPrice, currentPrice; // <-- Removed inflationRate variable.
char again;

do 
{
    cout << "enter the price of the item when you bought it: ";
    cin >> startingPrice;

    cout << "enter the price of the item today: ";
    cin >> currentPrice;

    cout << "the inflation Rate is: " << inflationRate(startingPrice, currentPrice) << "%"; // <-- Calling inflationRate

    cout << "would you like to try another item (y/n)?";
    cin >> again;

}while((again == 'Y') || (again =='y'));

return 0;

}

double inflationRate(double startingPrice, double currentPrice)
{
    return ((currentPrice - startingPrice) / startingPrice);
}