Member Avatar for JanraeMendoza
//==============================================================================//
// RPS (Rock Paper Scissors)
// Author: SoulPour777 / Janrae Mendoza
// A Simple C++ Game
// =============================================================================//
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
    string player;
    string player2;
    int wins;
    int loses;
    int roll;
    int draws;
    void error();
    void gamePlay();
    void Scene_Result_Display () {
        cout << "Player Wins: " << wins <<endl;
        cout << "Player Loses: " << loses <<endl;
        cout << "Draws: " << draws <<endl;
        cout << "Thank you for playing!" <<endl;
        cout << "-----------------------------" <<endl;
    };

    void start () {
    cout << "Let us play Rock, Paper, Scissors!" <<endl;
    cout << "Win as many as you can!" <<endl;
    cout << "<r> for Rock, <p> for Paper and <s> for Scissors!" << endl;
    gamePlay();
    };

    void playAgain () {
                cout << "Play again? <y> / <n> " << endl;
        cout << "Decision: ";
        cin >> player;
            if (player=="y") {
                gamePlay();
            } else if (player =="n") {
                Scene_Result_Display();
            }

    };


    void draw() {
        cout << "Rock....Paper.....Scissors!" <<endl;
        cout << "Draw!" << endl;
        draws++;
        playAgain();
    };

    void win() {
        cout << "Rock...Paper...Scissors!" <<endl;
        cout << "You win!" <<endl;
        wins++;
        playAgain();
    };

    void lose() {
        cout << "Rock....Paper.....Scissors!" <<endl;
        cout << "You lost!" << endl;
        loses++;
        playAgain();
    };



    void gamePlay () {
        cout << "Please have your choice: " <<endl;
        cout << "Choice: ";
        cin >> player;
            srand(time(0));
            roll = 1+rand()%3;
        switch (roll) {
             case 1:
                player2=="R";
                    if (player=="r") {
                        draw();
                    }
                    else if (player=="p") {
                        win();
                    }
                    else if (player=="s") {
                        lose();
                    } else {
                        error();
                    }
                break;
            case 2:
                player2=="P";
                     if (player=="r") {
                        lose();
                    }
                    else if (player=="p") {
                        draw();
                    }
                    else if (player=="s") {
                        win();
                    } else {
                        error();
                    }
                break;
            case 3:
                player2=="S";
                    if (player=="r") {
                        win();
                    }
                    else if (player=="p") {
                        lose();
                    }
                    else if (player=="s") {
                        draw();
                    } else {
                        error();
                    }
                break;
        }


    };

        void error() {
        cout << "You placed a wrong character choice!" <<endl;
        cout << "Please try again!" <<endl;
        gamePlay();
    };

        int main (){
        start();
        return 0;
        }

Recommended Answers

All 2 Replies

Yeah, so?

So, is this an example, or are you asking 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.