HarryGSn

Greek C++ Switch-SubProgram Examples

Jun 19th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. // Using nsp std to avoid using std:: prefix!
  4. using namespace std;
  5.  
  6. // SUB-PROGRAMS
  7.  
  8. void add();
  9. void subtraction();
  10. void multiplication();
  11. void division();
  12.  
  13. // GLOBAL VARIABLES
  14.  
  15. int oper;
  16. long num1;
  17. long num2;
  18.  
  19. // MAIN PROGRAM
  20.  
  21. int main()
  22. {
  23.     cout << "choose from the underneath nums to do a math operation:";
  24.     cout << "1 for add";
  25.     cout << "2 for sub";
  26.     cout << "3 for mult";
  27.     cout << "4 for div";
  28.  
  29.     cin >> oper;
  30.  
  31.     switch(oper)
  32.         {
  33.         case 1:
  34.             add();
  35.             break;
  36.         case 2:
  37.             subtraction();
  38.             break;
  39.         case 3:
  40.             multiplication();
  41.             break;
  42.         case 4:
  43.             division();
  44.             break;
  45.         default:
  46.             exit;
  47.             break;
  48.         }
  49.  
  50.     system("pause");
  51.     return 0;
  52. }
  53.  
  54. void add()
  55. {
  56.     cout << "grapse enan ari8mo";
  57.     cin >> num1;
  58.     cout << "grapse enan allon ari8mo";
  59.     cin >> num2;
  60.    
  61.     cout << "to a8roisma tous kanei : " << num1 + num2;
  62.  
  63. }
  64. void subtraction()
  65. {
  66.     cout << "grapse enan ari8mo";
  67.     cin >> num1;
  68.     cout << "grapse enan allon ari8mo";
  69.     cin >> num2;
  70.    
  71.     cout << "h diafora tous kanei : " << num1 - num2;
  72.  
  73. }
  74. void multiplication()
  75. {
  76.     cout << "grapse enan ari8mo";
  77.     cin >> num1;
  78.     cout << "grapse enan allon ari8mo";
  79.     cin >> num2;
  80.    
  81.     cout << "o pollaplasiasmos tous kanei : " << num1 * num2;
  82.  
  83. }
  84. void division()
  85. {
  86.     cout << "grapse enan ari8mo";
  87.     cin >> num1;
  88.     cout << "grapse enan allon ari8mo";
  89.     cin >> num2;
  90.    
  91.     cout << "h diairesh tous kanei : " << num1 / num2;
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment