通货膨胀率计算器

inflation rate calculator c++

本文关键字:计算器 通货膨胀率      更新时间:2023-10-16

我试图建立一个通货膨胀率计算器,但它不工作。我现在不在国内,用的是学校的电脑,所以所有的错误都是韩文,我已经翻译了,但不是很明白。

#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> ------ Build started: Project: testing, configuration: Debug Win32 ------

1> Build started: 2016-09-22 11:04:39 AM

1> InitializeBuildStatus:

1> "Debug testing. "a.

1> ClCompile:

1>所有输出都是最新的

1> ManifestResourceCompile:

1>所有输出都是最新的

1> LINK: fatal error LNK1123:转换到COFF时发生错误。或损坏的文件不正确。

1>

1>创建失败。

1>

1>运行时间:00:00:00.08

========== 构建: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);
}