Tuesday, July 28, 2009

C++ program question how does this look?

menu();





cin %26gt;%26gt; functionType;





while(functionType != 9)


{


cout %26lt;%26lt; "For fraction 1" %26lt;%26lt; endl;


cout %26lt;%26lt; "Enter the numerator: ";


cin %26gt;%26gt; numOne;


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "For fraction 1" %26lt;%26lt; endl;


cout %26lt;%26lt; "Enter the denominator: ";


cin %26gt;%26gt; denOne;


cout %26lt;%26lt; endl;





cout %26lt;%26lt; "For fraction 2" %26lt;%26lt; endl;


cout %26lt;%26lt; "Enter the numerator: ";


cin %26gt;%26gt; numTwo;


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "For fraction 2" %26lt;%26lt; endl;


cout %26lt;%26lt; "Enter the denominator: ";


cin %26gt;%26gt; denTwo;


cout %26lt;%26lt; endl;








switch(operator)


{


case '+':





cout %26lt;%26lt; addFractions() %26lt;%26lt; endl;


break;


}


case '-':


{





cout %26lt;%26lt; subtractFractions() %26lt;%26lt; endl;


break;


}


case '*':


{





cout %26lt;%26lt; multiplyFractions() %26lt;%26lt; endl;


break;


}


case '/':


{





cout %26lt;%26lt; divideFractions() %26lt;%26lt; endl;


break;


}





else





system("pause")

C++ program question how does this look?
As i remember


case const


thats mean a number not a string


try to create a new class to assign each operator to a number


enum i guess but not sure
Reply:well, if you're going to make them functions (which is very good practice and commendable, though more difficult), I'd pass the functions four values, so instead of


addFractions(), you're have


addFraction(int num1, int den1, int num2, int den2)


{


//do stuff.


}


No comments:

Post a Comment