Conditional Constructs 3

Description

The purpose of this challenge is to use if, if-else and switch statements. This challenge simulates a tiny part of a text-based RPG (role playing game)

Requirements

      1. Be sure to look at the sample interaction below to help your understanding of these requirements
      2. Declare an int called floor. Initialize this to 2 (You’re starting on the second floor)
      3. Declare an int called room. Initialize this to 0 (zero) (Zero means you’re not in a room; you’re in a hallway)
      4. Declare a string called weapon. 
      5. Declare an int called choice. Declare a char called action.
      6. Ask the user what floor to go to. Use the choice variable to receive the user’s input. Using a switch statement, set the floor variable to the appropriate value and display an appropriate message after the user makes a choice. (See the sample interaction)
      7. STOP! Have you read and implemented every instruction up to this point? Don’t skip steps. This is also a good point to do a test compile and run to make sure you are on the right track. It’s a good idea to write some code, compile, run, then write more code. Writing all the code out before your first compile almost guarantees more errors!
      8. Wait, seriously, did you read step 7?
      9. Display a message about encountering an enemy (See sample interaction)
      10. Ask which weapon you want to wield. Use the choice variable to receive this input, where a 1 represents a gun, and 2 represents an axe.
      11. Using a switch statement, in the case block for the gun, set weapon to “gun” and ask the user if you want to shoot a single shot, or empty the magazine. Use the action variable to receive this input. Write a nested switch statement in this block. If the user entered ‘s’, show a message “You have maimed the kestrel”. If the user entered ‘e’, show a message “You have minced the kestrel”. You decide how you handle the default case.
      12. In the same outer switch statement from Step 11, in the case block for the axe, set weapon to “axe” and ask the user if you want to take a small swing or a huge swing. Use the action variable to receive this input. Write a nested switch statement in this block. If the user entered ‘s’, show a message “Oof, the kestrel just got more upset”. If the user entered ‘h’, show a message “Feathers go flying and kestrel yelps in extreme pain and falls over”. You decide how you handle the default case.

DO NOT USE

Loops

Sample Interaction / Output

You're standing in the hallway by the staircase. Do you want to go 1-up or 2-down? 1

You are now on the 3rd floor

A wild three-headed kestrel has appeared and is looking at you menacingly. What weapon do you want to wield, 1-gun, 2-axe? 2

You are now wielding an axe. Do you want to take a (s)mall swing or a (h)uge swing? s

Oof, the kestrel just got more upset.

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-COND0003

Print Requirements