//game of rock paper sissors
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(3));//seed the random generater
int mychoice= ,rock,paper,sissors;
cout<<"enter rock,paper or sissors";
cin>>mychoice;
int choice = rand(3%) && rock,paper,sissors;
if(mychoice = rock && choice = paper)
cout<<"\nyou lose";
if(mychoice = paper && choice = rock)
cout<<"\nyou win";
if(mychoice = sissors && choice = rock)
cout<<"\nyou lose";
if(mychoice = rock && choice = sissors)
cout<<"\nyou win";
if(mychoice = paper && choice = sissors)
cout<<"\nyou lose";
if(mychoice = sissors && choice = paper)
cout<<"\nyou win";
else
cout<<"\nits a tie";
return 0;
}
need help with rock,paper,sissors code
I'm trying to make a simple game of rock,paper,sissors my code won't work here it is
What do you mean by "doesn't work"? Problems I can see:
If thats C++, its very messed up...
- In your if statements, use ==, not =. = means assignment, == means comparison.
- srand(time(3)) <-- That'll crash. Use NULL, not 3
- int mychoice= ,rock,paper,sissors; <-- What does that mean? Whats it supposed to do?
- int choice = rand(3%) && rock,paper,sissors; <-- Again, whats that supposed to do?
If thats C++, its very messed up...
i think i fixed it
#include<iostream>
#include<cstdlib>
#include<ctime>
#define rock 0
#define paper 1
#define sissors 2
using namespace std;
int main()
{
srand(time(3));//seed the random generater
int mychoice=0;
cout<<"enter rock(1),paper(2) or sissors(3)";
cin>>mychoice;
mychoice--;
int choice = rand()%3;
if((mychoice == rock )&& (choice = paper))
{
cout<<"\nyou lose";
}
else if((mychoice == paper)(choice = rock))
{
cout<<"\nyou win";
}
else if((mychoice == sissors))choice = rock))
{
cout<<"\nyou lose";
}
else if((mychoice == rock)(choice = sissors))
{
cout<<"\nyou win";
}
else if((mychoice == paper)(choice = sissors))
{
cout<<"\nyou lose";
}
else if((mychoice == sissors) && (choice = paper))
{
cout<<"\nyou win";
}
else
{
cout<<"\nits a tie";
}
return 0;
}
googl for a c++ tut
#include<iostream>
#include<cstdlib>
#include<ctime>
#define rock 0
#define paper 1
#define sissors 2
using namespace std;
int main()
{
srand(time(3));//seed the random generater
int mychoice=0;
cout<<"enter rock(1),paper(2) or sissors(3)";
cin>>mychoice;
mychoice--;
int choice = rand()%3;
if((mychoice == rock )&& (choice = paper))
{
cout<<"\nyou lose";
}
else if((mychoice == paper)(choice = rock))
{
cout<<"\nyou win";
}
else if((mychoice == sissors))choice = rock))
{
cout<<"\nyou lose";
}
else if((mychoice == rock)(choice = sissors))
{
cout<<"\nyou win";
}
else if((mychoice == paper)(choice = sissors))
{
cout<<"\nyou lose";
}
else if((mychoice == sissors) && (choice = paper))
{
cout<<"\nyou win";
}
else
{
cout<<"\nits a tie";
}
return 0;
}
googl for a c++ tut
Thats still not fixed.
On if((mychoice == rock )&& (choice = paper)) and the other similar lines, the second = still needs to be ==, and the srand(time(3)); should still crash, or at least not compile - time() takes a pointer to a structure to fill in, not an integer.
On if((mychoice == rock )&& (choice = paper)) and the other similar lines, the second = still needs to be ==, and the srand(time(3)); should still crash, or at least not compile - time() takes a pointer to a structure to fill in, not an integer.
Thanks but I've still got errorsfile
//game of rock paper sissors#include<iostream>#include<cstdlib>#include<ctime>#include<string>using namespace std;int main(){ srand(null(3));//seed the random generater int mychoice= rock||paper||sissors; cout<<"enter rock,paper or sissors"; cin>>mychoice; int choice = rand(3%); string choice = rock||paper||sissors; if(mychoice == rock && choice == paper) cout<<"\nyou lose"; if(mychoice == paper && choice == rock) cout<<"\nyou win"; if(mychoice == sissors && choice == rock) cout<<"\nyou lose"; if(mychoice == rock && choice == sissors) cout<<"\nyou win"; if(mychoice == paper && choice == sissors) cout<<"\nyou lose"; if(mychoice == sissors && choice ==paper) cout<<"\nyou win"; else cout<<"\nits a tie"; return 0;}
- srand(null(3)); should be srand(time(NULL)); (sorry for my rubbish explanation :P)
- int mychoice= rock||paper||sissors; evaluates to 1. You can change this line just to int mychoice;
- int choice = rand(3%); This also makes no sense. You probably want int choice = rand()%3
- What happened to the #define lines? They were correct.
- string choice = rock||paper||sissors; Also makes no sense
The thing about string, is probably because you typo'd the #include filename. It should be string, not sring.
Quote:Original post by mike25025
this should work
*** Source Snippet Removed ***
edit: frogot to seed
Aww, I wanted to see what other amusing versions of C++ he could come up with [crying]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement