2017-01-24 23 views
0

我是一個初學者試圖找出這個程序添加分數,同時也使他們的輸出結果打印出它的最低公分母形式。在這種形式下運行它從來沒有正常運行......試圖添加分數,同時也打印LCD

using namespace std; 

class Fraction { //Creates class Fraction 
private: //Makes data members private 
    int num; 
    int denm; 
}; 

int main() 
{ 
    int num; 
    int denm; 
    int num2; 
    int denm2; 
    int plus; 
    int plus2; 

    cout << "Please enter the numerator and denominator of the first fraction: " << endl; 
    cin >> num >> denm; 
    cout << "Please enter the numerator and denominator of the second fraction: " << endl; 
    cin >> num2 >> denm2; 
    plus = num*denm2 + denm*num2; 
    plus2 = denm*denm2; 
    cout << num << "/" << denm << " + " << num2 << "/" << denm2 << " = " << plus << "/" << plus2; 
    cout << "Hit 'enter' to exit..." << endl; 
} 
+1

你能否詳細說明「永遠不會正常運行」......問題是什麼?如果使用了正確的縮進(可能是複製/粘貼問題),並且由於不使用分數類,它也會有所幫助。 –

+0

究竟是'永不跑適當'?你能添加輸入和預期的輸出與獲得的輸出嗎? –

+0

似乎[爲我工作](http://rextester.com/WZK7668)至少有一個測試用例。 –

回答

0

你需要在保持輸出窗口打開的方式運行程序或修改它做到這一點。在這裏看到的例子:

How to keep the console window open in Visual C++?

的一種方式做到這一點在任何環境將cin最終return 0之前的另一個值 - 這會,當然,需要按比先進入其他的東西,但它達到了目的。

+0

謝謝!那對那部分起作用了,對添加部分有什麼建議? – Student1860