Applying the Switch and some other functions.

This is a discussion on Applying the Switch and some other functions. within the C Programming forums, part of the General Programming Boards category; Ok i'm using Borland ver 5.01 and below is the code i'm trying to do. I've shown this code to ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    5

    Exclamation Applying the Switch and some other functions.

    Ok i'm using Borland ver 5.01 and below is the code i'm trying to do. I've shown this code to a friend and he said i can actually use a switch function. I'm new to progamming but i don't want the exact coding but just want to know what and how to do it.

    And if possible i want to know if there's anything wrong with it like the
    int salesp[999], salesam[999], quarter[999];

    Thanks
    -Kendo411
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Jan 2004
    Posts
    14
    What a co-incidence! I just found this by accident.... I need to also find out how to use the switch function.... where are ya now 'Jaded Kendo'?....

    This is a Rek Law production....

    Oh yeah I e-mailed John Thorne and this is what he said to me:

    and with the programing course work, the paper work is worth most of the marks, and i am just trying to get it finished myself, but the main advice that i can give you is that if you got the lesson 11's program working in the extra lessons that they did before christmas, expand on that to get the course work program.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    Code:
    switch(value)
    {
        case val1:       // if value == val1
            ...code...   // do this code
            break;       // end of this case
        case val1:
            ...code...
            break;
        default:     // none of the above cases
            ...code...
            break;
    }
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    I would like to know why you are using 999 as the aray size. Do you really need that much?

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    14
    This person is doing the same work as me.... our situation is a $$$$ed up one.... any recommendations on where I can download a free compiler such as Borland 5.01?

  6. #6
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    He has a code to begin with.

    Try:
    http://www.cprogramming.com/compilers.html

  7. #7
    Registered User
    Join Date
    Jan 2004
    Posts
    5

    about array

    i know i put a really high value for the array size but because my tutor didn't specifically stated what value, i just assumed that 999 would more than enough. Does it matter actually even if i put 999 instead of 100+.?

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i just assumed that 999 would more than enough.
    That's a safe assumption in student code, but production programs will typically work with a great deal more than 999. But no matter how much you assume, there may still be more than you planned for, which is why a dynamic structure (one that grows and shrinks as needed) is preferable. So, while your idea of setting the size for far more than you will need is perfectly acceptable, keep in mind that it is a naive approach and best avoided.
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Jan 2004
    Posts
    5
    I didn't use the SWITCH command for my program but hey it was still a good practice (wish i had notice it earlier in the tutorial section).
    Talking about the tutorial section, i know it's mainly to do in C++ since they use 'cin' and 'cout' i can't seem to find anything gives a practise on the "while" function(it's called that right?) although i think it's similar to the 'if's, so does anyone know a site where it gives some exercises to do cause i know there is one but just couldn't find it. I've tried to do some exercise from a book but since i'm borrowing it from the library, they don't usually supply the CD (includes the examples and answers) to it so it's kinda hard to check what i'm suppose to see for my program.
    -Kendo411

  10. #10
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    While statements are easy.
    Code:
    while (comparison)
    {
        your code
    }
    The program loops as long as comparison it TRUE.
    Your code should change something in the comparison to eventually make it false.
    To exit the loop prematurely, use the break; statement.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

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