1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
void input(int &a_hrs,int &b_min,double &c_rate,char &d_res);//function 1
double billing_amount(int t_min,double h_rate,char reply);//function 2
int main()
{
cout<<"hewerwreo"<<endl;//to check whether current code or previous code is working
int hours,minutes,temp;
char response,rerun_option;
double hourly_rate,bill;
do
{
input(hours,minutes,hourly_rate,response);
temp=hours*60+minutes;
bill=billing_amount(temp,hourly_rate,response);
if(bill==0)
cout<<"THere is no charges for you"<<endl;
else
cout<<"Service charge:$ "<<bill<<endl;
cout<<"Do you run the program again:(Y/N) ";
cin>>rerun_option;
}while(rerun_option=='y' || rerun_option=='Y');
system("pause");
return 0;
}
//User Input Function
void input(int &a_hrs,int &b_min,double &c_rate,char &d_res)
{
int temp,minutes;
cout<<"Enter the hourly rate:$ ";
cin>>c_rate;
cout<<endl;
cout<<"Consulting Time:"<<endl;
cout<<"NOTE: Enter '0' for hours if the consulting time is less than a hour"<<endl;
cout<<"Hours: ";
cin>>a_hrs;
cout<<"\nMinutes: ";
cin>>b_min;
cout<<"Enter 'Y' or 'y' if your income less than or equal to 25000"<<endl;
cout<<"Enter 'N' or 'n' if your income greater than 25000"<<endl;
cout<<"'Y/y' or 'N/n': ";
cin>>d_res;
while(d_res!='Y' && d_res!='y' && d_res!='N' && d_res!='n')
{
cout<<"Invalid Input!"<<endl;
cout<<"Enter 'Y/y' or 'N/n': ";
cin>>d_res;
cout<<endl;
}
}
//billing amount calculating function
double billing_amount(int t_min,double h_rate,char reply)
{
double charge,m;
int h,rem_min;
if(reply=='Y' ||reply=='y')
{
if(t_min<=30)
{
charge=0;
}
else
{
rem_min=t_min-30;
if(rem_min<60)
{
charge=(h_rate*0.40*rem_min)/60;
}
else
{
h=rem_min/60;
m=rem_min%60;
charge=h_rate*h+h_rate*0.40*(m/60);
}
}
}
else
{
if(t_min<=20)
charge=0;
else
{
rem_min=t_min-20;
if(rem_min<60)
{
charge=h_rate*0.70*(rem_min/60);
}
else
{
h=rem_min/60;
m=rem_min%60;
charge=h_rate*h+h_rate*0.70*(m/60);
}
}
}
return charge;
}
|