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.

dusktreader commented: You'll never make int in Computer Science if you don't do your own homework +0

Recommended Answers

All 7 Replies

When I was in school, we were expected to do our own homework. Has this changed?

You need WIN32 application or console application?

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

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

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:

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?

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

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.