| | |
rock paper scissor program
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 0
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!
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!
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.
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Feb 2008
Posts: 55
Reputation:
Solved Threads: 0
ok here is some of the code that i have started on:
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?
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() //function protoypes void menu(); void userChoice(); void computerChoice(); int rock, paper, scissors; do { menu(); 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...
that should give you a random number between 1 & 3.
Chris
C++ Syntax (Toggle Plain Text)
#include <ctime> srand( (unsigned) time(NULL) ); randomnumber = rand() % 3 + 1;
that should give you a random number between 1 & 3.
Chris
Knowledge is power -- But experience is everything
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: reading data from txt to array
- Next Thread: invalid conversion
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






