that's doing your work for you, but okay:
Code:
#include<iostream>
#include <cstdlib>
#include<ctime>
using namespace std;
int main()
{
cout<<"Welcome To Charlies Slot machine"<<endl;
cout<<"press 1 to play 2 not to play"<<endl;
int a;
cin>>a;
if (a==1)
{
cout<<"You have chosen to play"<<endl;
cout<<"1 to roll 2 not to roll"<<endl;
int b;
cin>>b;
if (b==1)
{
int c;
srand(time(0));
c=1+rand()%6;
cout<<"you rolled"<<c<<" ";
int d;
srand(time(0));
d=1+rand()%6;
cout<<d<<" ";
int e;
srand(time(0));
e=1+rand()%6;
cout<<e<<endl;
if (c==d && d==e && c==e)
{
cout<<"you won";
}
} //second if
} //first if
return 0;
}
that's why you should space your code correctly
your code is a mess anyway, so i'm going to rewrite it for you:
Code:
#include<iostream>
#include<ctime>
#include <cstdlib>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int option,roll,nextroll;
bool win=true;
srand(clock());
cout<<"Welcome To Charlies Slot machine"<<endl;
cout<<"press 1 to play 2 not to play"<<endl;
cin>>option;
if (a==1)
{
cout<<"You have chosen to play"<<endl;
cout<<"1 to roll 2 not to roll"<<endl;
cin>>option;
if (option==1)
{
roll=1+rand()%6;
cout<<"you rolled"<<roll<<" ";
nextroll=1+rand()%6;
if(nextroll!=roll)
win=false;
roll=nextroll;
cout<<roll<<" ";
nextroll=1+rand()%6;
if(nextroll!=roll)
win=false;
roll=nextroll;
cout<<roll<<endl;
if (win)
cout<<"you won";
}
}
cout<<endl<<"Press any key to continue . . . ";
cin.get();
return 0;
}
even though that progam doesn't make much sense, because you would have to roll the dice the same number 3 times...