### function getting user input and passing it to another function

Hi all

Hope all are fine. I have a problem in which I have to find out billing amount of lawyer for his client. I need to get the following inputs from user: hourly rate,consultation time, yes or no response for the condition(employee income<=25000), then calculate the billing amount. the calculation part function I have done. But I dont how to get the user input as a function and return it to the main or other function which calculate billing amount.

I have given the code below, that I have done so far. But not working. Please help me.

code
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 #include #include #include using namespace std; double input();//function 1 double billing_amount(int minutes,double hourly_rate,char b);//function 2 int main() { input(); system("pause"); return 0; } //User Input Function double input() { int hrs,int min,double hr_rate,char a; double service_charge; cout<<"\nEnter the hourly rate:\$ "; cin>>hr_rate; cout<>hrs; int hrs2min=hrs*60; cout<<"\nMinutes: "; cin>>min; min=hrs2min+min; cout<<"Enter 'Y' or 'y' if your income less than or equal to 25000"<>a; while(a!='Y'||a!='y'||a!='N'||a!='n') { cout<<"Invalid Input!"<>a; cout<30 && minutes<60) { minutes=minutes-30; charge=hourly_rate*0.4*(minutes/60); } else { minutes=minutes-30; h=minutes/60; m=minutes%60; charge=hourly_rate*(h+(0.4*(m/60))); } } else { if(minutes<=20) { charge=0; } else if(minutes>20 && minutes<60) { minutes=minutes-20; charge=hourly_rate*0.7*(minutes/60); } else { minutes=minutes-20; h=minutes/60; m=minutes%60; charge=hourly_rate*(h+(0.7*(m/60))); } } cout<
You've got some mistakes:
 12 int hrs,int min,double hr_rate,char a; double service_charge;

you should separate variables using ;.

double input() should be changed to void input() since you don't return any values.

Finally, this is the correct way:
while(a!='Y'&& a!='y'&& a!='N'&& a!='n')

If you want to return a value to main, I suggest you declare a structure:
 1234 struct lawyer_info { //variables }

and changing the input function to lawyer_info input()
or void input(lawyer_info &input)

These might help:
http://www.cplusplus.com/doc/tutorial/structures/
http://www.cplusplus.com/doc/tutorial/functions2/ (passing by reference)
Last edited on
Hello maniax,

Thanks for you help. And sorry for the late reply. I used your first 3 points and solved my problem by somehow. here is the code

I didnt use struct because I havent studied that topic yet.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 #include #include #include 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"<>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<>a_hrs; cout<<"\nMinutes: "; cin>>b_min; cout<<"Enter 'Y' or 'y' if your income less than or equal to 25000"<>d_res; while(d_res!='Y' && d_res!='y' && d_res!='N' && d_res!='n') { cout<<"Invalid Input!"<>d_res; cout<
Topic archived. No new replies allowed.