If/Else Switch Case problem

This is a discussion on If/Else Switch Case problem within the C Programming forums, part of the General Programming Boards category; Hello! My brother recommended this site to me, he seemed to learn a lot from here. I'm working on If/Else ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    If/Else Switch Case problem

    Hello! My brother recommended this site to me, he seemed to learn a lot from here. I'm working on If/Else statements for a class, and I thought I had it down until I was thrown this curve ball.

    "Create an application that prints the verses of the song “The Twelve Days of Christmas”, in which the user enters the day (1-12) and each verse is printed. Use switch/case statements to break each pick into the verse. Also, make sure to use the “default” with the case statements if the user types an invalid number. On the twelfth day of Christmas, my true love sent to me, Twelve drummers drumming,
    On the eleventh day of Christmas, my true love sent to me, Eleven pipers piping,
    On the tenth day of Christmas, my true love sent to me, Ten lords a-leaping,
    On the ninth day of Christmas, my true love sent to me, Nine ladies dancing,
    On the eighth day of Christmas, my true love sent to me, Eight maids a-milking,
    On the seventh day of Christmas, my true love sent to me, Seven swans a-swimming,
    On the sixth day of Christmas, my true love sent to me, Six geese a-laying,
    On the fifth day of Christmas, my true love sent to me, Five golden rings,
    On the fourth day of Christmas, my true love sent to me, Four calling birds,
    On the third day of Christmas, my true love sent to me, Three French hens,
    On the second day of Christmas, my true love sent to me, Two turtle doves,
    On the first day of Christmas, my true love sent to me, A partridge in a pear tree.

    By the way, when a user hits 5, it should display phrases 5 – 1. When a user hits 11, it should display lines 11 – 1.

    Hint 1: Inside the case structure, stick with the SAME order of phrases that I have above.
    Hint 2: Loose the “break”.
    Hint 3: case 10: System.out.println(“On the tenth day of Christmas, my true love sent to me, Ten lords a-leaping, “);"


    I was never taught anything about case 10 or system.out.println. So I'm kinda lost. If anyone could just point me in the right direction I would be very grateful!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,992
    Quote Originally Posted by Pfinferno
    I was never taught anything about case 10 or system.out.println.
    The case 10 thing is just an example, similiar to what you have seen with switch statements and case labels. The system.out.println is likely to be the result of your instructor "porting" over this question from another class he/she taught, but forgetting to change the text. Use puts or printf instead.
    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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Here's a hint for you... this program is real easy and it can work because of a common error people make when writing switch()-case statements. You can actually break out of the mold and take advantage of it.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    Ah yes this turned out to be a lot easier than I thought. Thanks for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch and case problem.
    By jaja009 in forum C Programming
    Replies: 6
    Last Post: 03-29-2010, 08:15 AM
  2. switch/case problem
    By maxilog1009 in forum C Programming
    Replies: 3
    Last Post: 09-07-2009, 08:35 PM
  3. switch/case problem?
    By Wiiplayer12 in forum C++ Programming
    Replies: 2
    Last Post: 05-15-2008, 11:13 PM
  4. case switch problem
    By digdug4life in forum C++ Programming
    Replies: 10
    Last Post: 10-08-2005, 09:25 AM
  5. Switch/case problem
    By Ivan! in forum C++ Programming
    Replies: 4
    Last Post: 01-31-2003, 10:48 AM

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