im making a program that will let you play rock paper scissors with the computer.

the code will be in function format with a switch statement for the menu.

this is how it should look:

welcome to rock paper scissors!
select a choice
1. rock
2. paper
3. scissors
4. quit

choice: rock
you picked rock.
the computer picked paper

you lose. paper wraps rock

hit enter key to continue......

program should loop to menu again and continue until you decide to quit.
as you quit, it should display how many games you won and how many games the computer won along with any ties.

this is my assignment and im confused as to how my layout should be,

we have just learned how to use function, and since im still new to that aspect, its hard for me to apply it rather than just to one long block of code (this code has to be a function by the way)

any help would be appreciated.


Recommended Answers

All 6 Replies

Get out a piece of paper and a pencil.

Sketch out how you think the program should be broken up - you can use flowchart, psuedocode, whatever helps you organize your thoughts.

What are the main aspects? If you tried to write this as one massive main( ) function, what would be the logical parts you could isolate?

Looking at what you've written above, there's a menu, computer selecting choice, testing who won. Perhaps a couple other significant actions.

Work on that, post some code.

here is what i have:

1) display menu
2) ask for user choice
3) user input
--> display user input
4) computer choice (random)
5) test who wins
----> if statement?
6) display winner with statement
7) loop back to menu
---> repeat until quit
8) quit
---> show who won games/ties

That looks right to me, next state it to convert that into code, be it C++ or psuedo.
do each point indervidually, don't try and mix them up.


ok here is some of the code that i have started on:

#include <iostream>
using namespace std;

int main()

//function protoypes
void menu();
void userChoice();
void computerChoice();

int rock, paper, scissors;

cin >> userChoice;

while (userChoice < 1 || userChoice > 4)
cout << "please enter 1, 2, 3, or 4";
cin >> userChoice;

i know i havent written the actual functions yet...but how do i write a statemnent that will let the computer generate their own random choice? is there a special function to use?

im not gonna comment on errors in your code, since this may just be purposefull...

#include <ctime>

srand( (unsigned) time(NULL) );

randomnumber = rand() % 3 + 1;

that should give you a random number between 1 & 3.


Now use a switch case statement to use the input from the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.