我是一个初学者,试图找出这个添加分数的程序,同时也让他们的输出打印出结果中的最低公分母形式。以这种形式运行它永远不会正常运行...
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;
}
答案 0 :(得分:0)
您需要以保持输出窗口打开的方式运行程序或修改它以完成此操作。请参阅此处的示例:
How to keep the console window open in Visual C++?
在任何环境中执行此操作的一种方法是在cin
之前return 0
另一个值 - 当然,这会要求您按下先输入的其他内容,但它会为目的