natarajadithyan

Switch Case

Jul 21st, 2012
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream.h>
  2. void main()
  3. {
  4.   float a,b,i;
  5.   cout<< "This is a simple no GUI calculator which can Add, Subtract, Multiply, Divide.\n";
  6.   cout<< "Enter '1' to add, '2' to Subtact, '3' to Multiply, '4' to Divide.\n";
  7.   cin>> i;
  8.   cout<< endl;
  9.   switch(i)
  10.     {
  11.      case 1:
  12.      cout<< "Your option was Addition.\n";
  13.  
  14.      cout<< "Enter the First number...\n";
  15.      cin>> a;
  16.      cout<< endl;
  17.      cout<< "Enter the Second number...\n";
  18.      cin>> b;
  19.      cout<< endl;
  20.      cout<< "Sum of the numbers is "<<a+b;
  21.      cout<< endl;
  22.      break;
  23.     case 2:
  24.      cout<< "Your option was Subraction. Format is 'First number-Second number'.\n";
  25.  
  26.      cout<< "Enter the First number...\n";
  27.      cin>> a;
  28.      cout<< endl;
  29.      cout<< "Enter the Second number...\n";
  30.      cin>> b;
  31.      cout<< endl;
  32.      cout<< "Difference of the numbers is "<<a-b<<".\n";
  33.      break;
  34.     case 3:
  35.      cout<< "Your option was Multiplication. The Multiplication is only of two numbers.\n";
  36.  
  37.      cout<< "Enter the First number...\n";
  38.      cin>> a;
  39.      cout<< endl;
  40.      cout<< "Enter the Second number\n...";
  41.      cin>> b;
  42.      cout<< endl;
  43.      cout<< "Product of the numbers is "<<a*b<<".\n";
  44.      break;
  45.     case 4:
  46.      cout<< "Your option was Division. The first number is divided by the second number.\n";
  47.  
  48.      cout<< "Enter the First number...\n";
  49.      cin>> a;
  50.      cout<< endl;
  51.      cout<< "Enter the Second number...\n";
  52.      cin>> b;
  53.      cout<< endl;
  54.      cout<< "Difference of the numbers is "<<a/b<<".";
  55.      break;
  56.     default:
  57.     cout<< "The program does not understand your input. Try one of the the supported ones.\n";
  58.     break;
  59.   }
  60.  cout<< "Thank you for trying this program";
  61. }
Advertisement
Add Comment
Please, Sign In to add comment