We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,007 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Rock Paper Scissor

Hey everyone I am New here.... need some help with my coding for my college HW assignment.... I need to make a rock paper scissor game. I can think of the game in my brain on how I am gona code it but when I try to program it doesnt work.... here is some bit of my code.
I am playing against the computer and this is the beginning. my main question is on the loop and the randomness. I need the program to keep going and show score after every 3 times and the user can quit the game when ever they want by typing X instead of the number to select.

#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>

using namespace std;


int main()
{
    bool keepPlaying = true;
    string Name;
    char replay;
    int cpuSele, playerSele, gamePlayed, win, lose;
    gamePlayed = 0;
    win = 0;
    lose = 0;

    cout << "Please Enter your name: ";
    cin >> Name;
    cout << "\nWelcome " << Name << endl;

    srand(time(0));
    cpuSele = 1 + rand() % 3;

    cout << "Select one of the following with number: " << endl;
    cout << "1 = Rock" << endl;
    cout << "2 = Paper" << endl;
    cout << "3 = Scissor" << endl;
    cin >> playerSele;

    while(keepPlaying) //trying to loop here :S
        switch(cpuSele)
        case 1:
            if(playerSele == 1)
                cout << "Rock <===> Rock" << endl;
                cout << "TIE, try again" << endl;
                gamePlayed++;
                    cout << "Games Played: " << gamePlayed << endl;

//game should keep playing as long as it can go
//shows the score after every 3 games.
//user can quit anytime by pressing X || x


    system("pause");
    return 0;
}
3
Contributors
3
Replies
1 Week
Discussion Span
7 Months Ago
Last Updated
4
Views
xxwikkixx
Newbie Poster
14 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Where are you going to press "X"? What variable will get it?

I am playing against the computer and this is the beginning. my main question is on the loop and the randomness. I need the program to keep going and show score after every 3 times and the user can quit the game when ever they want by typing X instead of the number to select.

There are no questions in that question. Only your needs. You need to explain what your problem is, not the assignment's problem.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

You can try this.

char playerSele = 'a';

while( playerSele != 'x'|| playerSele != 'X') 
{

   cpuSele = 1 + rand() % 3 ;

   switch(cpuSele)
   {
       case 1:
             cin >> playerSele
             if( atoi(playerSele) == 1)
             {
               cout << "Rock <===> Rock" << endl;
               cout << "TIE, try again" << endl;
             }
             gamePlayed++;

             cout << "Games Played: " << gamePlayed << endl;

             break;

      case 2: // type your code  
      case 3: // type your code 

    }

}

Here I'm randomizing inside the loop. Also I used playerSele as character so that it can act for 1, 2, 3 and x, X too. I used atoi() to convert the character '1' to integer 1 for comparison with cpuSele.

np complete
Posting Whiz
385 posts since Sep 2010
Reputation Points: 18
Solved Threads: 36
Skill Endorsements: 0

sorry for the late reply I finished this project. thanks for help.

xxwikkixx
Newbie Poster
14 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0690 seconds using 2.75MB