# c_programming

This is a discussion on c_programming within the C Programming forums, part of the General Programming Boards category; Hi I have a problem whit this code: Code: double charge =2; //2\$ double houre; if(houre<=3) return charge; if(houre>3 && ...

1. ## c_programming

Hi
I have a problem whit this code:
Code:
```double charge =2; //2\$
double houre;
if(houre<=3)
return charge;

if(houre>3 && houre <=24)
/* charge must  increase whit 0.5\$
every houre.???
*/```

2. Please be more specific. What do you want this code to do? What exactly is your problem?

3. A parking charge is 2 dollor for up to three houres. After 3 houres the charge increase
0.5\$ every houre. and we can not park more than 24 houres.
My problem: if a person parks his car 5 houres.
The charge=(fisrt 3 houre = 2\$ +every houre 0.5\$)=4\$

4. Code:
```charge=2+(0.5*(houre-3))
return charge```
That code would return the fee for anything more than 24 hours. You'll probably want to include some sort of error message if hours is more than 24.

Thank you very much for your help.

6. but if I park my car 5.25 hourse.
first: 5.25-3=2.25
second: vi pay 0.5\$ every houre after 3 hourse. For 2.25 hourse we must pay 3\$
because for 2 hourse we pay 2\$ and 0,25 houre we should pay one dollor more.
How do I complete this code?
Code:
```charge=2+(0.5*(houre-3))
return charge```

7. How do you think you'd do it? There are many ways. You do know that you can do things across multiple lines. You don't have to try and figure out one single line of code to do what you want.

Quzah.

8. I tried to work on it, but I think I have a problem with 'return'. If I have a 'printf' that states the value of X, the 'return' command for evaluating X should be written before or after the printf?
Something else, how do you call upon a double? ("%.4f") ?
Thanks

9. When code reaches a 'return' statement, it immediately returns, or exits, the function. Thus:
Code:
```int foo( void )
{
printf("This line happens.\n");
return 0; /* This line happens, and the function immediately ends. */
printf("This line will never happen.\n");
}```
Here is a FAQ on using printf to format output.

Quzah.