Advertisement
max003003003

Untitled

Nov 26th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.05 KB | None | 0 0
  1. #include <iostream>
  2. #include<windows.h>
  3. #include<iostream>
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6. #include <unistd.h>
  7. #include <cstdlib>
  8. #include <ctime>
  9. #include <cstdlib>
  10. using namespace std;
  11.  
  12. int money=0;
  13. bool charger_status=false;
  14. bool charger_status2=true;
  15. int password=0;
  16. bool time_check=true;
  17. int time_mm;
  18. int t=1;
  19. int check_password_fail;
  20.  
  21. bool password_check(int pass )
  22.  
  23. {
  24.  
  25.     if(pass==password)
  26.     {
  27.         cout<<"correct password !!!!"<<endl;
  28.         Sleep(2000);
  29.         return true;
  30.     }
  31.     else
  32.     {   check_password_fail+=1;
  33.         cout<<"incorrect password"<<endl;
  34.         Sleep(2000);
  35.         return false;
  36.     }
  37.  
  38.  
  39. }
  40. void timer(int minute)
  41. {
  42.  
  43.         int h=0,m=0,s=0;
  44.        
  45.         s++;
  46.      while(true)
  47.     {
  48.         system("CLS") ;
  49.  
  50.          if(s==minute)
  51.          {
  52.              return;
  53.          }
  54.     if(s==60)
  55.     {
  56.       s=0;
  57.       m++;
  58.            if(m==60)
  59.             {
  60.               m=0;
  61.               h++;
  62.                   if(h==24)
  63.                     {
  64.                       h=0;
  65.                     }
  66.             }
  67.         }
  68.     printf("Charge time %d:%d:%d \n",h,m,s);
  69.     Sleep(1000);
  70.     s++;
  71.      }
  72. }
  73.  
  74. int generate_password()
  75. {
  76.     srand(time(NULL));
  77.     return  rand() % (10000 - 90000) + 10000 ;
  78.  
  79.  
  80. }
  81.  
  82. void charge(int m)
  83. {  
  84.     cout<<"plese connect cable to your device if finished please input 1"<<endl;
  85.     int choice;
  86.     cin>>choice;
  87.     while(!(choice==1))
  88.     {
  89.         cin>>choice;
  90.  
  91.     }
  92.     password=generate_password();
  93.     cout<<"your password : "<<password<<endl;
  94.     Sleep(3000);
  95.     timer(m);
  96.     charger_status=true;    
  97.     return;
  98. }
  99.  
  100. int money_check(int choice,int m)
  101. {
  102.     int temp_money=choice*30;
  103.     if(m==temp_money)
  104.     {
  105.          t=0;
  106.         charge(m);
  107.         return 0;
  108.     }
  109.     if(m>temp_money)
  110.     {
  111.         int result = m-temp_money;
  112.         t=0;
  113.         cout<<"return = "<<result<<"  baht."<<endl;
  114.         charge(temp_money);
  115.         return 0;
  116.     }
  117.     else
  118.     {
  119.      cout<<"not enough money return "<<m<<" baht."<<endl;
  120.      Sleep(3000);
  121.      timer(30);      
  122.      return 99;
  123.     }
  124. }
  125. void service ()
  126. {
  127.    
  128.     while(t)
  129.     {
  130.         int choice;
  131.         system("CLS") ;
  132.         cout<<"1) 30 minute  30 baht."<<endl;
  133.         cout<<"2) 60 minute  60 baht."<<endl;
  134.         cout<<"3) 90 minute  90 baht."<<endl;
  135.         cout<<"please input choice <<";
  136.         cin>>choice;
  137.         switch (choice)
  138.         {
  139.         case 1:
  140.             cout<<"please insert money << ";
  141.             cin>>money;
  142.            if( money_check(choice,money)==99 ){return; }
  143.            
  144.             break;
  145.         case 2:
  146.             cout<<"please insert money << ";
  147.             cin>>money;
  148.             money_check(choice,money);
  149.             if( money_check(choice,money)==99 ){return; }
  150.             break;
  151.         case 3:
  152.             cout<<"please insert money << ";
  153.             cin>>money;
  154.             money_check(choice,money);
  155.             if( money_check(choice,money)==99 ){return; }
  156.             break;
  157.         default:
  158.             cout<<"please try again."<<endl;            
  159.             return;
  160.             break;
  161.         }
  162.      }
  163. }
  164. int main()
  165. {
  166.     cout<<"Wellcome  "<<endl;
  167.     check_password_fail=0;
  168.     int choice =0;
  169.     while(true)    
  170.     {
  171.         choice=0;
  172.         if(check_password_fail==3)
  173.             {
  174.                 system("CLS") ;
  175.                 cout<<"\n Please contrack call center to unlock your phone.  "<<endl;
  176.                 Sleep(3000);  
  177.                 return 0;
  178.             }
  179.            
  180.         system("CLS") ;
  181.         cout<<"------------menu---------------"<<endl;
  182.         cout<<"1) charge your mobile phone "<<endl;
  183.         cout<<"2) get your mobile phone back "<<endl;
  184.         cout<<"input choice<< ";
  185.         cin>>choice;        
  186.         if(choice==1)
  187.           {
  188.              
  189.                 if(!charger_status)
  190.                 {      
  191.                t=1;
  192.                    service();                      
  193.                 }
  194.                else
  195.                 {
  196.                        
  197.                    cout<<"please get your mobile phone"<<endl;
  198.                    Sleep(500);
  199.                 }
  200.                
  201.          }
  202.          else if(choice==2)
  203.          {
  204.        
  205.              if(charger_status)
  206.               {
  207.                     cout<<"Enter your password << " ;
  208.                     int p;
  209.                     cin>>p;
  210.                     if(password_check(p))
  211.                        {
  212.                             system("CLS") ;
  213.                             generate_password();
  214.                             cout<<"finished"<<endl;
  215.                             Sleep(2000);
  216.                             system("CLS") ;
  217.                             check_password_fail=0;
  218.                             cout<<"---------------Thank You----------------"<<endl;
  219.                             Sleep(2000);
  220.                             charger_status=false;
  221.      
  222.                        }
  223.                }
  224.              else
  225.                {
  226.                        t=1;                
  227.                        service();
  228.          
  229.                }
  230.           }
  231.     }
  232.     return 0;
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement