Reply
Nov 26 2006
By: BGamer00090 Treasure Hunter 5377 posts
Offline

C++ Slot Machine "help!"

2 replies 10 views Edited Nov 26, 2006
I need help with a program I'm writing in C++ class. I need to make a slot machine that displays 3 boxes that display the numbers 1,or 2, or 3 at random. When all the boxes have 1 you win 4 tokens... 2 8 tokens... and 3 12 tokens. If they don't do those three things then you lose a token. You start out with 100 tokens.
 
Here's what I have so far:
 
/*Viva las Vegas 11/17/06*/
#include<iostream.h>
#include<lvp\random.h>
void main (){
randomize();
int n1,n2,n3,t,x;
char P;
t=100;
cout<<"--$$$Virtual Slot Machine$$$--"<<endl;
cout<<"You Have "<<t<<" tokens. Want to pull (y/n)?"<<endl;
cin>>P;
 
 do{n1= int(1+random(3));
    n3= int(1+random(3));
    n2= int(1+random(3));
   cout<<"";
   cout<<"";
   cout<<"";
   t=t-1;
   for(int x=1; x<=3; x++);
   cout<<"You have "<<(t)<<" tokens. Want to pull again (y/n)?"<<endl;
   cin>>P;
   }while(P=='y');
     if (P=='n')
     cout<<"***Game Over*** FINAL SCORE: "<<t<<" tokens"<<endl;
     if(n1&&n2&&n3==1)
      t=t+4;
 if(n1&&n2&&n3==2)
 t=t+8;
   if(n1&&n2&&n3==3)
   t=t+12;
 
    if(t==0)
    cout<<"Oh no!! You're out of money!! Get out of this casino!";
 
}
 
 
 
The only problem with the program is that when you win they don't give you the tokens. Can anyone here help (it would be greatly appriciated).
Photobucket - Video and Image HostingPhotobucket - Video and Image HostingPhotobucket - Video and Image HostingPhotobucket - Video and Image HostingPhotobucket - Video and Image HostingPhotobucket - Video and Image HostingPhotobucket - Video and Image Hosting
Photobucket - Video and Image Hosting
Message 1 of 3 (10 Views)
Reply
0 Likes
Sackboy
Registered: 07/31/2006
Offline
606 posts
 

Re: C++ Slot Machine "help!"

Nov 26, 2006
show me wht it looks like
Message 2 of 3 (10 Views)
Reply
0 Likes
Keyblade Wielder
Registered: 02/20/2005
Offline
10631 posts
 

Re: C++ Slot Machine "help!"

Nov 26, 2006
This is coming from someone that doesn't know C++, but the

 if(n1&&n2&&n3==2)
 t=t+8;
   if(n1&&n2&&n3==3)
   t=t+12;

is outside of your actual gameplay loop, and aren't you ending the function, or at least beginning the loop again, before you actually award their tokens.  This would mean the program never actually gets to those lines.

The variables could also be a bit less confusing, and if you want to save your fingers, the += operator does the same thing as "variable = variable + x"



Message Edited by Spo8 on 11-26-2006 03:25 AM
Message 3 of 3 (10 Views)
Reply
0 Likes