0

I'm a beginner trying to figure out this program of adding fractions while also making their output print the result in it's lowest common denominator form. Running it in this form never runs properly...

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;
}
ilim
  • 4,477
  • 7
  • 27
  • 46
Student1860
  • 138
  • 2
  • 17
  • 1
    Could you elaborate on "never runs properly" ... what is the issue? It would also help if proper indentation was used (could be a copy/paste issue) and the Fraction class was omitted since you're not using it. – Matt Davis Jan 24 '17 at 06:26
  • What exactly is 'never runing properly' ? Could you addict inputs ans expected outputs vs obtained outputs ? – J. Piquard Jan 24 '17 at 06:29
  • Seems to [work for me](http://rextester.com/WZK7668) for at least one test case. – Igor Tandetnik Jan 25 '17 at 00:32
  • @mattsplat The program when run shows the first input and when I enter it, it immediately displays gibberish and exits before I can see anything. – Student1860 Jan 25 '17 at 02:53

1 Answers1

0

You'll need to run the program in a fashion that keeps the output window open or modify it to accomplish this. See here for examples:

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

One way to do this in any environment would be to cin another value before the final return 0 - this would, of course, require you to press something other than enter first, but it serves the purpose.

Community
  • 1
  • 1
Matt Davis
  • 361
  • 1
  • 4
  • 10