Advertisement
Guest User

Untitled

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