Site hosted by Angelfire.com: Build your free website today!

Program 18MST

Program 18

C++ Konrad Dzwonkiewicz

 

Using Switch with char values

 

This is a sample program that will act as a calculator.

 

Have the program ask for the operation by entering the appropriate symbol. This will process through the switch where you check all possible symbols that could be entered

(+, -, *, x, X, \, /, ^, and anything else you can think of that I’ve missed).

If they enter a bad one input gracefully with a parting message.

      (this could be your default in the switch…)

 case ‘+’: add(first, second);

             break;

   default: cout<<”Bad Input…Now quitting”<<endl;

               for((long int)x=0; x<8000000; ++x); //pause

            }

 

Ask the numbers to be operated on (two numbers)

 

Produce the output in one of the five functions (multiply, add, divide, subtract or power)

 

Sample run…

Text Box: Enter operation: *
Enter two numbers: 12 20

 

 

 

Sample output…

Text Box: 12*20=240	                  

 

 

Text Box: Warning on Claymore Anti-Personal Mine
DO NOT EAT
Text Box: Label on Fender Guitar
Made in America.
Parts from Japan.
Assembled in Mexico.
Text Box: Sign in Smoky Mountain National Park, Tennessee
If tunnel is dark, remove sunglasses.