2016-09-22 143 views
-4

我正試圖建立一個通貨膨脹率計算器,但它不起作用。 我目前出國並使用學校電腦,所以所有的錯誤都以韓文顯示,我已經翻譯過,但並不完全理解它們。通貨膨脹率計算器C++

#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> ------生成開始:項目:測試,配置:調試的Win32 ------

1>構建開始:2016年9月22日11時04分: 39 AM

1> InitializeBuildStatus:

1> 「調試\ testing.unsuccessfulbuild」 連接(接觸)一個。

1> ClCompile:

1>所有輸出都是最新的。

1> ManifestResourceCompile:

1>所有輸出是否是最新的。

1> LINK:致命錯誤LNK1123:在轉換爲COFF期間發生錯誤。或損壞的文件不正確。

1>

1>未能建立。

1>

1>執行時間:00:00:00.08

==========生成:0成功,1失敗,最近0,0跳過== ========

+1

您同時有函數和變量的名稱'inflationRate',改變一個他們 – vu1p3n0x

+0

您可以嘗試使用translate.google並向我們顯示這些錯誤 – YakovL

回答

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); 
} 
+0

謝謝!現在工作 – Fernanda