cin %26gt;%26gt; functionType;
while(functionType != 9)
{
.
.
.
}
if (functionType != 9)
switch(functionType)
{
case '+':
cout %26lt;%26lt; addFractions %26lt;%26lt; endl;
}
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")
} //end while
return 0;
}
C++ how can I write this apropriately?
You're doing a great job of it so far, what's missing?
Don't forget to run a loop to fetch the operator (* or / or +, etc) and to fetch the desired numbers from the user.
Catch the user input in a variables and examine them to see if it's an operator or a number. Then feed the operator and numbers to your existing code...
while(!done)
cout %26lt;%26lt; "Provide function type"
cin %26gt;%26gt; functionType;
if(functionType == '\' || functionType =='*' ||....)
{
cout %26lt;%26lt; "Provide 1st number "
cin %26gt;%26gt; n1;
cout %26lt;%26lt; "Provide 2nd number "
cin %26gt;%26gt; n2;
if(isnum(n1) %26amp;%26amp; isnum(n2))
done = 1;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment