Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<stdlib.h>
- #include <cstdlib>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int money=0;
- bool charger_status=false;
- int password=0;
- bool time_check=true;
- int time_mm;
- bool password_check(int pass )
- {
- if(pass==password)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void timer(int minute)
- {
- int h=0,m=0,s=0;
- system("CLS") ;
- s++;
- for(;;)
- {
- if(s==minute)
- {
- return;
- }
- if(s==60)
- {
- s=0;
- m++;
- if(m==60)
- {
- m=0;
- h++;
- if(h==24)
- {
- h=0;
- }
- }
- }
- printf("%d:%d:%d \n",h,m,s);
- _sleep(1000);
- s++;
- }
- }
- int generate_password()
- {
- srand(time(NULL));
- return rand() % (10000 - 90000) + 10000 ;
- }
- void charge(int m)
- {
- cout<<"plese connect cable to your device if finished please input 1"<<endl;
- int choice;
- cin>>choice;
- while(!(choice==1))
- {
- cin>>choice;
- }
- password=generate_password();
- cout<<"your password : "<<password<<endl;
- _sleep(3000);
- timer(m);
- charger_status=true;
- return;
- }
- void money_check(int choice,int m)
- {
- int temp_money=choice*30;
- if(m==temp_money)
- {
- charge(m);
- }
- if(m>temp_money)
- {
- int result = m-temp_money;
- cout<<"return = "<<result<<" baht."<<endl;
- charge(temp_money);
- }
- else
- {
- cout<<"not enough money return "<<m<<" baht."<<endl;
- return;
- }
- }
- void service ()
- {
- int choice;
- cout<<"1) 30 minute 30 baht."<<endl;
- cout<<"2) 60 minute 60 baht."<<endl;
- cout<<"3) 90 minute 90 baht."<<endl;
- cout<<"please input choice <<";
- cin>>choice;
- switch (choice)
- {
- case 1:
- cout<<"please insert money << ";
- cin>>money;
- money_check(choice,money);
- break;
- case 2:
- cout<<"please insert money << ";
- cin>>money;
- money_check(choice,money);
- break;
- case 3:
- cout<<"please insert money << ";
- cin>>money;
- money_check(choice,money);
- break;
- default:
- cout<<"please try again."<<endl;
- return;
- break;
- }
- }
- int main()
- {
- cout<<"Wellcome "<<endl;
- int choice =0;
- while(true)
- {
- cout<<"------------menu---------------"<<endl;
- cout<<"1) charge your mobile phone "<<endl;
- cout<<"2) get your mobile phone back "<<endl;
- cout<<"input choice<< "<<endl;
- cin>>choice;
- switch (choice)
- {
- case 1:
- if(!charger_status)
- {
- service();
- }
- break;
- case 2:
- if(charger_status)
- {
- cout<<"Enter your password <<"<<endl;
- int p;
- cin>>p;
- if(password_check(p))
- {
- generate_password();
- cout<<"finished"<<endl;
- charger_status=false;
- }
- }
- else
- {
- service();
- }
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement