Created
November 29, 2011 14:41
-
-
Save edhedges/1405027 to your computer and use it in GitHub Desktop.
Fraction Calculator Main code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************** | |
* Name: Eduardo Hernandez-Hedges * | |
* Date: 10/20/2010 * | |
* Assignment: Project 5: Fractions * | |
*********************************************** | |
* This project asks the user for two fractions | |
then asks the user whether they want to add, | |
subtract, multiply, or divide them. Then it | |
prints out the correct reduced value * | |
***********************************************/ | |
#include <iostream> | |
using namespace std; | |
#include "fraction.h" | |
/********************************************** | |
* main function: this function handles the io | |
of the program and stores sends the inputted | |
values to fraction.cpp so that it can return | |
the correct output values. * | |
***********************************************/ | |
int main(){ | |
Fraction f; | |
Fraction fTwo; | |
Fraction fThree; | |
int fraction[4]; | |
char lulz[2]; | |
cout << "Enter the first fraction (e.g. 9/5): " ; | |
cin >> fraction[0] >> lulz[0] >> fraction[1]; | |
cout << "Enter the second fraction (e.g. 9/5): "; | |
cin >> fraction[2] >> lulz[0] >> fraction[3]; | |
cout << "Enter the operator (+, -, *, /): "; | |
cin >> lulz[1]; | |
if(lulz[1] != '+' && lulz[1] != '-' && lulz[1] != '*' && lulz[1] != '/'){ | |
cout << "Wrong input" << endl; | |
return 0; | |
} | |
f.setValues(fraction[0], fraction[1]); | |
fTwo.setValues(fraction[2], fraction[3]); | |
if(lulz[1] == '+') fThree = f.plus(fTwo); | |
else if(lulz[1] == '-') fThree = f.minus(fTwo); | |
else if(lulz[1] == '*') fThree = f.times(fTwo); | |
else if(lulz[1] == '/') fThree = f.divide(fTwo); | |
fThree = fThree.reduce(); | |
cout << "\n" << fraction[0] << lulz[0] << fraction[1] << lulz[1] << fraction[2] << lulz[0] << fraction[3] << " = "; | |
fThree.print(); | |
cout << "Press any key to terminate program."; | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment