Advertisement
haithienht

C++ Final Assignment 3

May 29th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <ctype.h>
  4.  
  5. int choice;
  6.  
  7. void hienMenu(){
  8.    
  9.     printf("\n*****Arithmetic Program*****");
  10.     printf("\n         1.Add");
  11.     printf("\n         2.Subtract");
  12.     printf("\n         3.Multiply");
  13.     printf("\n         4.Devide");
  14.     printf("\n         5.Quit");
  15. }
  16.  
  17. void tinhtoan(){
  18.     float x,y;
  19.     printf("\nEnter the first number: "); scanf("%f", &x);
  20.     printf("\nEnter the second number: "); scanf("%f", &y);
  21.    
  22.     switch(choice){
  23.         case 1:
  24.             printf("\nThe result %.0f + %.0f is %.6f", x,y,x+y); break;
  25.         case 2:
  26.             printf("\nThe result %.0f - %.0f is %.6f", x,y,x-y); break;
  27.         case 3:
  28.             printf("\nThe result %.0f x %.0f is %.6f", x,y,x*y); break;
  29.         case 4:
  30.             printf("\nThe result %.0f : %.0f is %.6f", x,y,x/y); break;
  31.     }
  32. }
  33.  
  34. int main(){
  35.    
  36.     do{
  37.         hienMenu();
  38.         printf("\nPlease enter your choice (1-5): ");
  39.         scanf("%d", &choice);
  40.        
  41.         switch(choice){
  42.             case 1: tinhtoan(); break;
  43.             case 2: tinhtoan(); break;
  44.             case 3: tinhtoan(); break;
  45.             case 4: tinhtoan(); break;
  46.             case 5: return 0; break;
  47.         }
  48.         fflush(stdin);
  49.        
  50.         if(choice>=1&&choice<=5){
  51.             printf("\nContinue? (Y/N) ");  
  52.            
  53.             char choice2 = getchar();
  54.            
  55.             switch(tolower(choice2)){
  56.                 case 'y': break;
  57.                 case 'n': return 0; break;
  58.                 default: break;
  59.             }
  60.         }
  61.         else{
  62.             printf("\nIncorect!\n");
  63.         }
  64.            
  65.     }while(choice!=5);
  66.    
  67.     getch();
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement