Jul 5, 2012 at 1:56am UTC
First of all, the iostream interface (if we can call it this way) is better be done outside your function, that is, in main. So your function should take two parameters, the rate and the type of customer, a double and a char.
Could you carry on after this?
Last edited on Jul 5, 2012 at 1:56am UTC
Jul 5, 2012 at 2:01am UTC
I'm stuck of getting parameter pass back to main function, that's why I try to figure out how it work 1st, I know I should take 2 parameter..
Jul 5, 2012 at 2:10am UTC
Did you copy/paste this code from your editor? You missed an end brace '
} ' for the last condition, plus it's
else not
else if for the final condition.
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
double PayRatesOne(char c)
{
double r;
if (c == 'W' )
{
r = 4.50;
return (r);
}
else if (c == 'M' )
{
// ...
}
// ...
}
int main()
{
// ...
char customer;
cout << "Enter the type of customer (W/M/S) \n" ;
cin >> customer;
// ...
}
Last edited on Jul 5, 2012 at 2:13am UTC
Jul 5, 2012 at 3:01am UTC
how u can use the PayRatesOne to receive user input? and then the r? I need to calculate it in the main function, i avoid global variable..
Jul 5, 2012 at 4:28am UTC
my concern :
I want to pass user input pass to function at main..
Jul 5, 2012 at 5:00am UTC
Use a reference and the parameter you pass will actually be modified.
Jul 5, 2012 at 5:14am UTC
Use pass by reference concept.
void PayRatesOne(double & r)
{
char Customer;
cout << "Enter the type of customer (W/M/S) > ";
cin >> Customer;
if(Customer == 'W')
r = 4.50;
else if(Customer == 'M')
r = 4.00;
else if(Customer == 'S')
r = 3.50;
}
int main()
{
double Rates;
PayRatesOne(Rates);
cout << Rates;
return 0;
}
please try to follow some coding conventions that will be useful to you in future.
Last edited on Jul 5, 2012 at 5:25am UTC
Jul 5, 2012 at 5:17am UTC
uh what is this?
I want to pass user input which in main, to function.. not get user input in function..
Last edited on Jul 5, 2012 at 5:22am UTC
Jul 6, 2012 at 6:49am UTC
I don't think he understood the concept, because basically TightCoder and I provided him with the same code as above, with some missing statements...
:S
Jul 6, 2012 at 7:21am UTC
no ToniAz, HiteshVaghani1 solved my needs..
thanks HiteshVaghani1!