#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;
}
how do i make this loop?
can someone help me make this game loop?
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.
Ask if you have ?s.
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.
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 .
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]
Also, even if you prefer to spell it sissors, it's still wrong. [wink]
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?.
#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";}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement