if/else statements

For a project we are doing in class it involves fractions and since im begging im a little confused on the if/else statements. What im basicly trying to make it do is say if the wholenumber = 0 then just display the fraction but if the numerator = 0 then display just the whole number. It is doing it right but its displaying the fraction first and then the whole number. I know the reason its doing that is because im making two if statements and its telling it to check if the wholenumber is 0 and display the fraction and then checking to see if numerator is 0 and display the fraction. What i want it to do is to check to see if wholenumber = 0 to just show fraction but if the numerator is to just display the wholenumber. Anyways any help would be appreciated and i don't know if its confusing or not to you but im just not getting it.


Also another thing is when I display the calculations i want it to display the fractions like say 2/3 + 2/3= 4/3 not just 1.3333-

Any help will be appreciate and im not looking for an answer or code just need some help on the way im thinking or maybe im missing something.

CODE:

#include<iostream>

using namespace std;


struct Fraction{
double numerator, denominator;
};

int main()
{
Fraction aFraction, bFraction, cFraction ;
double wholenumber, wholenumber2, wholenumber3;
double calculation;
double calculation2;

cout<<"Enter a whole number: ";
cin>>wholenumber;

cout<<"Enter the numerator: ";
cin>>aFraction.numerator;

cout<<"Enter the denominator: ";
cin>>aFraction.denominator;

if (aFraction.denominator == 0)
aFraction.denominator = 1;
if (wholenumber !=0 || aFraction.numerator !=0 || aFraction.denominator !=0)
cout<<"You entered "<<wholenumber<<" "<<aFraction.numerator<<" / "<<aFraction.denominator<<endl;
else
if (wholenumber == 0)
cout<<"You entered "<<aFraction.numerator<<" / "<<aFraction.denominator<<endl;
else (aFraction.numerator == 0);
cout<<"You entered "<<wholenumber<<endl;

cout<<"Enter a whole number and then enter a fraction separating the numerator from the denominator by a space"<<endl;
cin>>wholenumber2>>bFraction.numerator>>bFraction.denominator;

cout<<"You entered "<<wholenumber2<<" "<<bFraction.numerator<<" / "<<bFraction.denominator<<endl;

calculation =wholenumber + wholenumber2 + aFraction.numerator/aFraction.denominator + bFraction.numerator/bFraction.denominator;

cout<<"Your two numbers added together: " <<calculation<<endl;

cout<<"Enter a fraction separating the numerator from the denominator by a space"<<endl;
cin>>wholenumber3>>cFraction.numerator>>cFraction.denominator;

cout<<"You entered "<<wholenumber3<<" "<<cFraction.numerator<<" / "<<cFraction.denominator<<endl;

calculation2 = wholenumber+ wholenumber2 + wholenumber3 + aFraction.numerator/aFraction.denominator + bFraction.numerator/bFraction.denominator + cFraction.numerator/cFraction.denominator;

cout<<"Your three numbers added together: "<<calculation2<<endl;


return 0;
}
nvm i figured it out now, thank you anyway :).
Topic archived. No new replies allowed.