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?
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
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"