Advertisement
Guest User

Untitled

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