Hi guy
i'm a 2 months colleage student of Computer Science in Foundation years. and My Teacher give a first exercise in C Programing. The exercise is:
A Sport Club have 2 price to go in. from 13pm to 16pm cost 5\$ and from 16pm to 19pm cost 8\$. Then a boy going in at 14pm and get out at 17pm. So How much he have to pay? so what the code? this is my code but it's wrong >.<
Code:
```#include <stdio.h>
void main()
{     int In,Out;
printf("input In=");
scanf("%d",&In);
printf("input Out=");
scanf("%d",&Out);
if(In>13)
if(Out<16)
else if(In>16)
else if(out<19)
if (in>13 & out>19)

}```

2. Originally Posted by khmerkid
Then a boy going in at 14pm and get out at 17pm.
Note that it does not matter what time the boy leaves, so you should ignore the "get out" timing.

3. There are just two possible computations:

*the boy enters during the first period and pays less to get in

or

*the boy enters during the second period, and pays more to get in.

The rest of the data is irrelevant, so you don't need to nest your if statements.

4. Hello fellow Computer Science student

Your code should look with something like this :

I'm on Windows and this may not be right, I haven't tried it.

Code:
```#include <stdio.h>
#include <math.h>
int main()
{     int In,Out;
scanf("%d",&In);
if (In>=13&&In<=16) {printf("The boy is paying \$5");}
else (if(In>16&&In<=19) {printf("The boy is paying \$8");}
return(1);
}
```

Something like this. You'll have to do another if for when the boy gets in at <13 or >19 and in that case do a printf saying the Gym is closed, I'm guessing.

Hope it helps, Dean.

5. Originally Posted by DeanWinchester
Hello fellow Computer Science student

Your code should look with something like this :

I'm on Windows and this may not be right, I haven't tried it.

Code:
```#include <stdio.h>
#include <math.h>
int main()
{     int In,Out;
scanf("%d",&In);
if (In>=13&&In<=16) {printf("The boy is paying \$5");}
else (if(In>16&&In<=19) {printf("The boy is paying \$8");}
return(1);
}
```

Something like this. You'll have to do another if for when the boy gets in at <13 or >19 and in that case do a printf saying the Gym is closed, I'm guessing.

Hope it helps, Dean.
dean, posting complete code as answers is against this forums policy. so, please don't do it!

6. Originally Posted by joybanerjee39
dean, posting complete code as answers is against this forums policy. so, please don't do it!
Oh, I wasn't aware of this.
I didn't give him the complete code though, just a basic idea.

7. Originally Posted by DeanWinchester
Oh, I wasn't aware of this.
I didn't give him the complete code though, just a basic idea.
it's ok for now. but you should have a look at the forum policyAnnouncements - C Programming

8. Think of how it would work if you weren't coding it, write the structure out on a piece of paper or something.

Once you know how it will work, it's then your job to put that into working C.