-2

hey guys i just want to ask for your help about the source code of ROCK PAPER SCISSORS game on c++, the rules of the game is that, the user and the computer will battle, the game consist of 5 rounds ONLY,and first player who score 3 out of 5 wins, the computer will select randomly from ROCK, PAPER, SCISSORS. The program will also display the winner every after round.The one who will score most wins in 5 rounds will be declared winner.. Please help. Thanks. i need to pass this one tomorrow so i'm counting on you guys, thanks.

Votes + Comments
You'll never make int in Computer Science if you don't do your own homework
6
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by dflatt
0

you could try making an attempt, thats generally a good way to make a start on it

0

just analyze it believe in yourself....that's just a simple program....start it little by little...or what we say "Divide and Conquer"

0

You didn't mention how you handle the draw's, so I decided that they didn't count for the round-count. So in my case, first at 3 wins.

Hope it helps!

#include <iostream>
#include <string>
#include <ctime>
int main()
{
    const std::string ch = "rps";
    unsigned short scores[2] = {0,0};
    srand(static_cast<unsigned>(time(NULL)));
    while (scores[0] + scores[1] < 5) {
        char ui, ci = ch[rand()%3];
        std::cout << "r,p or s?";
        std::cin >> ui;
        short lost = ((ui == 0x72 && ci == 0x70) || (ui == 0x70 && ci == 0x73) || (ui == 0x73 && ci == 0x72));
        std::string what = lost ? ". You lose.." : ". You win!"; 
        what = (ui == ci) ? ". It's a draw" : what;
        std::cout<<"round "<< scores[0]+scores[1]+1<<". Cpu had: "<<ci<<what<<'\n';
        if (!(ui == ci)) scores[lost]++;
    }
    std::cout << ((scores[0] > scores[1]) ? "User" : "CPU") << " won";
}

:twisted:

Edited by Nick Evan: n/a

0

how do can i use the header file iostream,string and c time? the only one i used is stdio.h and conio.h...how's that?

0

how do can i use the header file iostream,string and c time? the only one i used is stdio.h and conio.h...how's that?

i have a bridge for sale btw

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.