how do i make this loop?

Started by
6 comments, last by dalleboy 19 years, 6 months ago
can someone help me make this game loop?

#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
    const int rock = 1;
    const int sissors = 2;
    const int paper = 3;
    
    int MyChoice;
    srand(time(0));//seed the random generater
    int Choice = rand() % 3;
    cout<<"rock(1), paper(2), sissors(3)\n";
    cin>>MyChoice;
    
    if((MyChoice == rock) && (Choice == paper))
    {
         cout<<"you lose";
    }
    if((MyChoice == rock) && (Choice == sissors))
    {
        cout<<"you win";
    }
    if((MyChoice == paper) && (Choice == sissors))
    {
        cout<<"you lose";
    }
    if((MyChoice == paper) && (Choice == rock))
    {
        cout<<"you win";
    }
    if((MyChoice == sissors) && (Choice == rock))
    {
        cout<<"you lose";
    }
    if((MyChoice == sissors) && (Choice == paper))
    {
        cout<<"you win";
    }
    if((MyChoice == rock) && (Choice == rock))
    {
        cout<<"tie";
    }
    if((MyChoice == paper) && (Choice == paper))
    {
        cout<<"tie";
    }
    if((MyChoice == sissors) && (Choice == sissors))
    {
        cout<<"tie";
    }
    
    cin>>Choice;
    return 0;
}
-----------------------------------Panic and anxiety Disorder HQ
Advertisement
Make a new bool variable called done. Seperate from the point where you want the loop to begin to where you want it to end (or create a whole new function, which I recommend) and put all of that in a while(!done) {} loop.

Ask if you have ?s.
Things change.
no offense, but i believe that i have seen you post before about the same game. then too you misspelled "scissors".

again, just giving a heads up to save some possible embarassment.
Quote:Original post by Anonymous Poster
no offense, but i believe that i have seen you post before about the same game. then too you misspelled "scissors".


I know I like to spell scissors like that .
-----------------------------------Panic and anxiety Disorder HQ
You'll also want to set the bool done to false before entering the loop, and to true somewhere inside the loop when the user wants it. So you might add another option after scissors, say 4. Then add a if (MyChoice == 4) done = true;

Also, even if you prefer to spell it sissors, it's still wrong. [wink]
My stuff.Shameless promotion: FreePop: The GPL god-sim.
Also, rand()%3 will give you a number from 0 to 2. You should use rand()%3+1.
Quote:Original post by nagromo
Also, rand()%3 will give you a number from 0 to 2. You should use rand()%3+1.

It must not of pasted the +1 or something?.
-----------------------------------Panic and anxiety Disorder HQ
#include <iostream>#include <cstdlib>#include <ctime>enum Hand{   Rock,   Paper,   Scissors};Hand winHand[] = { Paper, Scissors, Rock };int main(){   srand(time(0));   int playChoice;   while (std::cout << "rock(1), paper(2), scissors(3)\n", std::cin >> playChoice && playChoice >= 1 && playChoice <= 3)   {      Hand compHand = Hand(rand() % 3);      Hand playHand = Hand(playChoice - 1);      if (compHand == playHand)         std::cout << "tie\n";      else if (winHand[compHand] == playHand)         std::cout << "you win\n";      else         std::cout << "you lose\n";   }   std::cout << "bye\n";}
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]

This topic is closed to new replies.

Advertisement