I recently missed 2 class periods in my computer programming course and now I am far behind and I need someones help, don't worry the following programs are examples and are not for a grade in any way or form - need to know how to do these so I can get my hw done.
1) Write a switch statement that, for two given integers A and B, and a give character operation, computes and displays A + B, A - B, A * B, or A / B according to whether operations is +, -, *, /, and display displays and illegal-operator message if it is not one of these.
2) I will post example 2 on a more later date
Anyway there you have it and I would appreciate any remarks, hints, and advice you have on this matter. Just so its clear this program is just an example and doesn't count for a grade, just needs to be made known to me so I know how to do my hw programs and tests.
Please / Thank you.
Computer Progamming(C++) examples?
Go to your school's lab during the professor's LAB HOURS. You can get help outside of class time that way.
Reply:Send me all your C++ questions.
I will send you the answers
iyiogrenci@yahoo.com
Reply:int A = 10;
int B = 10;
char opc;
cout %26lt;%26lt; "enter operation: ";
cin %26lt;%26lt; opc;
switch(opc)
{
case '+':
cout %26lt;%26lt; "A + B = " %26lt;%26lt; A+B %26lt;%26lt; endl;
break;
case '-':
cout %26lt;%26lt; "A - B = " %26lt;%26lt; A-B %26lt;%26lt; endl;
break;
case '*':
cout %26lt;%26lt; "A * B = " %26lt;%26lt; A*B %26lt;%26lt; endl;
break;
case '/':
cout %26lt;%26lt; "A / B = " %26lt;%26lt; A/B %26lt;%26lt; endl;
break;
default:
cout %26lt;%26lt; " illegal operation" %26lt;%26lt; endl;
}
I guess the important thing is to remember your "break" statements because they are real easy to forget.
Reply:switch( operator)
{
case '+' : printf( "A + B = %d", A+B );
case '-' : printf( "A - B = %d", A-B );
case '*' : printf( "A * B = %d", A*B );
case '/' : printf( "A / B = %d", A/B );
default : printf( "Operator unknown." );
}
carnation
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment