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;
}

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.

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.

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

Be a part of the DaniWeb community

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