Advertisement
fjraito

Code 1 - Pizza

Apr 21st, 2019
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Menu{
  5.    
  6.     private:
  7.  
  8.     public:  
  9.         void writeMenu(){
  10.             cout<<"1. Order Pizza"<<endl;
  11.             cout<<"2. Pay"<<endl;
  12.             cout<<"3. Exit"<<endl; 
  13.         }
  14.         void writePizzas(){
  15.             cout<<"1. Meat lover pizza (@ Rp. 80000,-)"<<endl;
  16.             cout<<"2. Vegetarian pizza (@ Rp. 50000,-)"<<endl;
  17.             cout<<"Which pizza do you want to order[1-2]: ";
  18.         }
  19. };
  20.    
  21. struct data{
  22.     int total;
  23. }pizza1, pizza2;
  24.  
  25. int main(){
  26.    
  27.     system("cls");
  28.     Menu menu;
  29.     menu.writeMenu();
  30.     int input;
  31.     cin >> input;
  32.     if(!cin){
  33.         cin.clear();
  34.         cin.ignore();
  35.         main();
  36.     } else {
  37.         switch(input){
  38.             case 1:
  39.                
  40.                 STARTHERE:
  41.                     menu.writePizzas();
  42.                     cin>>input;
  43.                     if(!cin){
  44.                         cin.clear();
  45.                         cin.ignore();
  46.                         system("cls");
  47.                         goto STARTHERE;
  48.                     } else {
  49.                         switch(input){
  50.                             case 1:
  51.                                
  52.                                 ++pizza1.total;
  53.                                 break;
  54.                             case 2:
  55.                                
  56.                                 ++pizza2.total;
  57.                                 break;
  58.                                
  59.                             default:
  60.                                 goto STARTHERE;
  61.                                 break;     
  62.                         }
  63.                     }
  64.                     cout<<"Thank you..."<<endl;
  65.                     main();
  66.                 break;
  67.                
  68.             case 2:
  69.                
  70.                 if(pizza1.total > 0 || pizza2.total > 0){
  71.                     cout<<"You have ordered "<<pizza1.total<<" Meat Lover Pizza(s) and "<<pizza2.total<<" Vegetarian Pizza(s)."<<endl;
  72.                     cout<<"Total price : "<<(pizza1.total*80000)+(pizza2.total*50000)<<endl;
  73.                    
  74.                     ASKMONEY:
  75.                         cout<<"Input your money [minimum Rp. "<<(pizza1.total*80000)+(pizza2.total*50000)<<"] :";
  76.                         cin>>input;
  77.                         if(!cin){
  78.                             cin.clear();
  79.                             cin.ignore();
  80.                             system("cls");
  81.                             goto ASKMONEY; 
  82.                         } else {
  83.                             if(input>=(pizza1.total*80000)+(pizza2.total*50000)){
  84.                                 cout<<"Your change : Rp. "<<input-(pizza1.total*80000)+(pizza2.total*50000)<<endl;
  85.                                 cout<<"Thank you..."<<endl;
  86.                                 cin.clear();
  87.                                 cin.ignore();
  88.                                 getchar();
  89.                             }  
  90.                         }
  91.                 } else {
  92.                     cout<<"You are not buy anything.."<<endl;
  93.                     cin.clear();
  94.                     cin.ignore();
  95.                     getchar();
  96.                 }
  97.                
  98.                 main();
  99.                 break;
  100.                
  101.             case 3:
  102.                
  103.                 cout<<"Thank you..."<<endl;
  104.                 exit(0);
  105.                 break;
  106.                
  107.             default: break;
  108.         }  
  109.     }  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement