rock, paper, scissors game: logical operators & switch statements

This is a discussion on rock, paper, scissors game: logical operators & switch statements within the C++ Programming forums, part of the General Programming Boards category; i'm writing a simple program for the game rock, paper, scissors. would i use an if statement or a switch ...

  1. #1
    Registered User helloalyssa's Avatar
    Join Date
    Sep 2010
    Posts
    25

    rock, paper, scissors game: logical operators & switch statements

    i'm writing a simple program for the game rock, paper, scissors.

    would i use an if statement or a switch statement to store both r and R as rock?
    Last edited by helloalyssa; 10-07-2010 at 10:13 PM. Reason: okay i did not figure it out. lol

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    Well one alternative for translating the user input into a value within a variable would be to use a switch statement with 'r', 'R', 'p', 'P', 's', and 'S' as the cases. If doing that then a switch statement would be preferable to six if-statements.

    However, you could also convert the input to uppercase first and then you only have three cases to deal with.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  2. Another rock paper scissor question
    By mattflick in forum C Programming
    Replies: 11
    Last Post: 09-29-2005, 09:41 PM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. PRS Help
    By SpudNuts in forum C Programming
    Replies: 10
    Last Post: 08-07-2005, 01:14 PM
  5. Rock, Paper, Scissors game help
    By MillaTime in forum Game Programming
    Replies: 4
    Last Post: 09-08-2002, 05:55 PM

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