Slot Machine

I got all this so far !!!

Nex is ..

First build in support for writing output to an output file.

2 Make a copy of your existing program and modify the new program to be array based or to use functions or both. It does not have to work exactly like the original but it must be playable in a similar manner.

Implement a minimum of two arrays or functions

add several other programming techniquessuch as string handling, switch statements, and so forth.

/* Slot Machine Program by Harde*/

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

using namespace std;

int main()

int x,a, b, c, token=4;

<<"\t*              Welcome to slot machine.                *\n"
<<"\t*  Would you like to play? (1 to play, 2 not to play)  *\n"
{cout<<"You have "<<token<< " tokens\n\n"
<<"Pull? (1 to pull, 2 not to pull)\n\n";


a = 1+rand() %10;
b = 1+rand() %10;
c = 1+rand() %10;
//       b = a;
//       c = a;

cout<<"\t\t"<<a<<"          "<<b<<"          "<<c<<"\n\n";


if(a==b && b==c)

cout<<"You win\n\n";
else if(a==b || b==c || a==c)

cout<<"You got two out of three\n\n";


cout<<"You lose\n\n";


return 0;

Recommended Answers

All 2 Replies

Use CODE tag and PROPER indentation.
Explain exactly what problem you are facing.

Are you trying to record all your cout's to an output file?
To get started...

Caps in the following code are up to you to choose.

//Necessary declarations
      ofstream CHOOSE_NAME;"FILE_NAME.TXT");
      //Now change all your cout's to...
      //    cout -----> CHOOSE_NAME
      //    i.e. CHOOSE_NAME << "You lose"
      //    CHOOSE_NAME becomes the same as cout, except cout is your screen and
      //    CHOOSE_NAME is your output file

      //Don't forget to close your file.

Sorry if you already know this, I assumed you don't since it isn't in your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.