munin
+ Reply to Thread
Results 1 to 3 of 3

Thread: problem in c++

  1. #1
    Join Date
    Oct 2007
    Posts
    1

    Unhappy problem in c++

    can anyone help me turn this 2 player game of paper, rock and scissor into a player versus computer type?please..i badly need it..


    # include <iostream>
    using namespace std;
    int main () {
    char a,b;
    int d,e;
    char ans;
    do {
    cout << "This is a game called Jack en Poy\n";
    cout <<"Player *, please select your move:" << endl
    << "*. Rock" << endl
    << "2. Scissors" << endl
    << "*. Paper";
    cout << "What is your move?\n";
    cin >> d;
    if (d==*) {
    cout << "Player *'s move is rock.";
    }
    else if (d==2){
    cout << "Player *'s move is scissors.";
    }
    else if (d==*){
    cout << "Player *'s move is paper.";
    }
    cout << "\nPlayer 2, please select your move:"<< endl
    << "*. Rock" << endl
    << "2. Scissors" << endl
    << "*. Paper";
    cout << "\nWhat is your move?\n";
    cin >> e;
    if (e==*) {
    cout << "Player *'s move is rock.";
    }
    else if (e==2){
    cout << "Player *'s move is scissors.";
    }
    else if (e==*){
    cout << "Player 2's move is paper.";
    }
    cout << "\nThe result is: \n";
    if (d==* && e==*){
    cout << "It is a tie!";
    }
    else if (d==2 && e==2) {
    cout << "It is a tie!";
    }
    else if (d==* && e==*) {
    cout << "It is a tie!";
    }
    else if (d==* && e==2){
    cout << "Player * wins!";
    }
    else if (d==* && e==*) {
    cout << "Player 2 wins!";
    }
    else if (d==2 && e==*) {
    cout << "Player * wins!";
    }
    else if (d==2 && e==*){
    cout << "Player 2 wins!";
    }
    else if (d==* && e==*) {
    cout << "Player * wins!";
    }
    else if (d==* && e==2) {
    cout << "Player 2 wins!";
    }
    cout << "\nRun the program again?(y/n)\n";
    cin >> ans;
    } while (ans!='n');
    return 0;
    }

  2. #2
    Join Date
    Sep 2006
    Posts
    1,649
    Err, what errors are you getting exactly?

    BTW, I made the exact same thing long time ago, using if-else loops. I didn't know about the swtich() statement then, it'll make your project much easier, and it would've made mine easier as well. Anyway, here's my old code:

    [PHP]//Rock Paper Scissors game by Moonbat
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    int main()
    {
    srand((unsigned)time(0));
    int choice;
    int compchoice = (rand()&#*7;2)+*;
    cout << "Welcome to ~ Rock Paper Scissors ~!! I assume you know how to play,";
    cout << " so lets begin. You are playing against the computer. Type 0 for";
    cout << " rock, * for paper, and 2 for scissors\n";
    cin >> choice;

    if (choice == 0)
    {
    if (compchoice == 0)
    cout << "It's a tie!\n\n\n\n";
    else if (compchoice == *)
    cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
    else if (compchoice == 2)
    cout << "Rock beats scissors! You win!\n\n\n\n";
    }

    if (choice == *)
    {
    if (compchoice == 0)
    cout << "It's a tie!\n\n\n\n";
    else if (compchoice == *)
    cout << "Paper beats rock! You win!\n\n\n\n";
    else if (compchoice == 2)
    cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
    }

    if (choice == 2)
    {
    if (compchoice == 0)
    cout << "It's a tie!\n\n\n\n";
    else if (compchoice == *)
    cout << "Scissors beat paper! You win!\n\n\n\n";
    else if (compchoice == 2)
    cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
    }
    return main();
    }[/PHP]

    P.S. - Like I said, this is old code and has a lot of bad programming habits in it, like using return main. Also, I wouldn't do what you are doing (declaring two variables in one statement) it's better to just declare them one at a time, or use an array.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  3. #3
    Join Date
    Jan 2005
    Posts
    623
    Tell her c++ is a lame language to create a paper rock scissors game with. Then send her here: [url=http://boninroad.com/syntax******/games/rockpaperscissors.php]Paper Rock Scissors[/url]
    [url=http://www.syntax******.info/tools/services.php]Speed Up Windows XP[/url]
    [url=http://www.syntax******.info/tools/ip.php]Get An Ip Address[/url]
    [url=http://www.syntax******.info/tools/base_converter.php]Base Converter[/url]
    --------------------------------
    [URL=http://www.boninroad.com/syntax******/]Old Site[/URL]
    [URL=http://www.syntax******.info]Comming Soon[/URL]

+ Reply to Thread

Similar Threads

  1. problem
    By minaaaa in forum General discussion
    Replies: 3
    Last Post: 05-11-2013, 06:37 AM
  2. Problem In C++
    By Vipul Motiwala in forum Programming
    Replies: 7
    Last Post: 01-15-2007, 11:14 AM
  3. I got a problem
    By Gabriel in forum Security & Encryption
    Replies: 2
    Last Post: 09-01-2006, 06:41 PM
  4. Problem...
    By liquinn in forum Internet Privacy
    Replies: 2
    Last Post: 08-04-2006, 01:28 PM
  5. another msn problem
    By Unregistered in forum Viruses and Trojans
    Replies: 4
    Last Post: 06-11-2004, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts