Slot Machine -- i want your opinion!

Ok, so since i'm new to c++ i was looking for some exercises and my friend told me to do a slot machine. So i thought to myself, why not?
I want your opinion because im sure there are better and shorter ways to do what i did.
Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*  CREATED BY: BONW
   MADE: 15/12/2010  */
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main(){
    cout << "      ||||||||||||||||||||SLOT MACHINE||||||||||||||||||||\n" << endl;
    int usermoney = 5000;
    int an1;
    char name[20];
    cout << "Name: "; cin >> name;
    cout << endl;
    cout << "You will start with 5000 euros. \nAnd you will loose 150 euros each time you loose. \n But you will win 300 euros each time you win." << endl;
    do{
    cout << "1.Play" << endl;
    cout << "2.Leave the slot machine" << endl;
    cout << "> "; cin >> an1;
    cout << endl << endl;
    if(an1 == 1){
        system("CLS");
    cout << "You have inserted 5000 euros. You are now ready to play." << endl;
    char pull[3];
    int random_integer;
    do{
    do{
    cout << "Type \"pull\" to pull the lever.\n";
    cout << "> "; cin >> pull;
    if(strcmpi(pull, "pull")==0){
    cout << "You pulled the lever." << endl;
    srand((unsigned)time(0));
    random_integer = (rand()%20)+1;
    cout << "The number was: " << random_integer << "." << endl;
    switch(random_integer){
    case 10:
    system("CLS");
    usermoney = usermoney + 300;
    cout << "YOU WIN!!! ***300 EUROS WERE ADDED***\n" << name <<"'s money: " << usermoney <<endl;
    break;
    default:
    system("CLS");
    usermoney = usermoney - 150;
    cout << "You loose. Try again.***150 EUROS WERE LOST***\n" << name <<"'s money: " << usermoney << endl;
    break;
    }

    }
    else{
    cout << "Only \"pull\" works." << endl << endl;
    }
    }
    while(!strcmpi(pull, "pull")==0);
     }
     while(usermoney > 0);
     switch(usermoney){
         case 5300:
     ofstream prize;
     prize.open("SLOTMACHINE.txt");
     prize << "***THIS IS OFFICIAL***" << endl;
     prize << name << "HAD 5300 EUROS ON THE SLOT MACHINE!" << endl;
     prize.close();
     cout << "Saved your 5300 euros in SLOTMACHINE.txt" << endl << endl;
     break;
     }
if(usermoney <= 0){
cout << "You ran out of cash." << endl;
exit(EXIT_FAILURE);
}
    }
    else if(an1 == 2){
    cout << "Exiting the slot machine." << endl;
    exit(EXIT_FAILURE);
    }
    else{
    cout << "Either 1 or 2." << endl;
    }
    }
    while(an1 != 1 && an1 !=2);
    cin.get();
    cin.get();
    return 0;
}

If you know about some other exercises, i'd be glad to try them out.
Thank you...
-bonw
It won't run on Codelite with g++.The errors are:

C:/C++/Projects/main.cpp:30: error: 'strcmpi' was not declared in this scope
C:/C++/Projects/main.cpp:32: error: 'time' was not declared in this scope
C:/C++/Projects/main.cpp:53: error: 'strcmpi' was not declared in this scope
Last edited on
You could try a test your memory game where the player has to enrter some remeber some numbers. Tell me your email and I will be able to send you the released program; the sourcecode was lost.
cap_one_fsc@live.com.pt Anyone can add if it's c++ related. (:
And @I am a Cpp beginner, i use Code::Blocks. You might want to try it on that.
Last edited on
You should receive my email now
I didn't get it. And i have a problem with a new exercise.
Topic archived. No new replies allowed.