Please Help for this Newbie Code

This is a discussion on Please Help for this Newbie Code within the C Programming forums, part of the General Programming Boards category; Hi guy i'm a 2 months colleage student of Computer Science in Foundation years. and My Teacher give a first ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    Question Please Help for this Newbie Code

    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 >.<
    Sorry for bad english.
    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. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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. #4
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    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; printf("When did the boy sign in ?"); 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. #5
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    107
    Quote Originally Posted by DeanWinchester View Post
    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; printf("When did the boy sign in ?"); 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. #6
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by joybanerjee39 View Post
    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. #7
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    107
    Quote Originally Posted by DeanWinchester View Post
    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. #8
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  2. Newbie - error in code
    By Chris361 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2003, 12:12 PM
  3. Please help me with this simple code. newbie here.
    By stehigs321 in forum C Programming
    Replies: 3
    Last Post: 09-29-2003, 10:49 PM
  4. OMG just STFU and HELP a NEWBIE with HIS CODE !!!!!!!!11
    By Dual-Catfish in forum Party Board
    Replies: 6
    Last Post: 07-14-2003, 07:09 AM
  5. newbie here.....need someone to look at my code
    By aml822 in forum C++ Programming
    Replies: 1
    Last Post: 11-28-2001, 09:40 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21