imageAll right, I may have written this slot machine code, however, I am not claiming it is mine, it was on a very old thumbdrive I found (it had 500 megabytes capacity so it was very old, also had some pictures of my last dog as a puppy, Gidget).

In the past, most VC++ or C++ projects used console output, nice for the instructors, nice for the students, really boring for the rest of the world.  The rest of the world doesn’t care about what language you use in your code, and by that I mean this: All software programmers in the world make up a “rounding” error in the World Population, maybe. 

So if you are here because you are concerned about where XNA and so forth has disappeared to, then welcome. 

If you aren’t worried like me, then welcome as well.  If you are here to learn about how to program Metro with C++, welcome.  If you are here because you have a homework problem that asks you create a slot machine solution, then please come back after you do your homework.  Or not.

Here is the code, which is pretty simple, actually it is quite simple, and the user interface is extremely boring.  It is one main method, uses the evil goto statement, but it does use a switch, kinky.

Code Snippet
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>//cout and endl,
  4. #include <conio.h>//for getch(), see http://msdn.microsoft.com/en-us/library/078sfkak(v=vs.100).aspx
  5. #include <stdlib.h>//rand()
  6. #include <stdio.h>//puts, printf
  7. #include <time.h>//for time()
  8. using namespace std;
  9. bool bSpin();
  10. void main()
  11.     {
  12.         int _coins=5;
  13.         srand(time(0));
  14.         _banner: system("cls");
  15.         cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
  16.         cout<<" +++++++   Welcome to the Flying Circus Want to Take Flight? ++++++++++"<<endl;
  17.         cout<<"===========PRESS========> (y)es (n)o <======PRESS======================"<<endl;
  18.         cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
  19.         unsigned int _userkey=getch();
  20.         int _userselection=0;
  21.         bool _userwin=false;
  22.  
  23.         putch(_userkey);
  24.  
  25.  
  26.             switch(_userkey)
  27.             {
  28.                 case 'Y'|'y':
  29.                     goto game;
  30.                     break;
  31.                 case 'N'|'n':
  32.                     return;
  33.                     break;
  34.                 default:
  35.                     system("cls");
  36.                     goto _banner; //goto, really?  Should be method.
  37.             }
  38.         game:
  39.             while(_coins!=0)
  40.             {
  41.                 system("cls");
  42.                 cout<<"Coins: "<<_coins<<endl;
  43.                 printf("bSpin?\n1. Yes\n2. No \n");
  44.                 cin>>_userselection;
  45.                 if(_userselection==1)
  46.                     _userwin=bSpin();
  47.                 else
  48.                     goto _banner;
  49.                 if(_userwin)
  50.                     _coins++;
  51.                 if(!_userwin)
  52.                     _coins--;
  53.                 _userwin=false;
  54.                 if(_coins==0)
  55.                     puts("Sorry, you are out of coins");
  56.             }
  57.         }
  58.         bool bSpin(void)
  59.         {
  60.             system("cls");
  61.             int values[3]={0, 0, 0};
  62.  
  63.             for(int i=0;i<3;i++)
  64.             {
  65.                 values[i]=(rand()%3)+1;
  66.                 printf("%i \t", values[i]);
  67.             }
  68.  
  69.             if(values[0]==values[1] && values[1]==values[2])
  70.             {
  71.                 cout<<endl<<"Winner!!! ";
  72.                 system("Pause");
  73.                 return true;
  74.             }
  75.             else
  76.             {
  77.                 cout<<endl<<"Crash  \n"<<endl;
  78.                 system("pause");
  79.                 return false;
  80.             }                            
  81.         }