rock paper scissor program

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2008
Posts: 55
Reputation: afg_91320 is an unknown quantity at this point 
Solved Threads: 0
afg_91320 afg_91320 is offline Offline
Junior Poster in Training

rock paper scissor program

 
0
  #1
Oct 16th, 2008
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.

thanks!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,674
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: rock paper scissor program

 
0
  #2
Oct 16th, 2008
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.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: afg_91320 is an unknown quantity at this point 
Solved Threads: 0
afg_91320 afg_91320 is offline Offline
Junior Poster in Training

Re: rock paper scissor program

 
0
  #3
Oct 16th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: rock paper scissor program

 
0
  #4
Oct 16th, 2008
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.

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 55
Reputation: afg_91320 is an unknown quantity at this point 
Solved Threads: 0
afg_91320 afg_91320 is offline Offline
Junior Poster in Training

Re: rock paper scissor program

 
0
  #5
Oct 16th, 2008
ok here is some of the code that i have started on:
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5.  
  6. //function protoypes
  7. void menu();
  8. void userChoice();
  9. void computerChoice();
  10.  
  11. int rock, paper, scissors;
  12.  
  13. do
  14. {
  15. menu();
  16. cin >> userChoice;
  17.  
  18. while (userChoice < 1 || userChoice > 4)
  19. {
  20. cout << "please enter 1, 2, 3, or 4";
  21. cin >> userChoice;
  22. }

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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: rock paper scissor program

 
0
  #6
Oct 16th, 2008
im not gonna comment on errors in your code, since this may just be purposefull...

  1. #include <ctime>
  2.  
  3. srand( (unsigned) time(NULL) );
  4.  
  5. randomnumber = rand() % 3 + 1;

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

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 122
Reputation: kenji is an unknown quantity at this point 
Solved Threads: 8
kenji's Avatar
kenji kenji is offline Offline
Junior Poster

Re: rock paper scissor program

 
0
  #7
Oct 16th, 2008
Now use a switch case statement to use the input from the user.
And she said "Let there be light" and on the seveth day Windows booted.
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC