Lotto simulation, comment please

A real simulation on how gambling wastes money

main.cpp

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>

#include "concor.h"

using namespace std;

int main(int nNumberofArgs,char* pszArgs[])
{
    int money = 50;
    int additive = 0;
    char input,input2;
    int number = 0;
    int number2 = 0;
    int color_number = 1;
    int pin = 0;
    int rpin = 0;
    int choice = 0;

    for(;;)
    {
        additive = 0;
        number = 0;
        number2 = 0;
        setcolor(cyan,black);
        cout << "Welcome to the lotto! Entering will deduct $10 from your bank account." << endl;
        setcolor(green,black);
        cout << "You currently have: $" << money << endl;
        setcolor(dark_red,black);
        cout << "Would you like to proceed? (Y/N): ";
        setcolor(yellow,black);
        cin >> input;
        setcolor(7,black);
        cout << endl;

        switch(input)
        {
            case 'y':
            case 'Y':
            srand((unsigned)time(0));
            color_number = 1 + rand() % (15);
            if(money == 0)
            {
                cout << "Warning, you have 0 dollars left. Quit or get money? (Q/M): ";
                setcolor(red,black);
                cin >> input2;
                setcolor(7,black);
                switch(input2)
                {
                    case 'q':
                    case 'Q':
                    cout << endl << "Thank you, come again!" << endl;
                    return 0;
                    case 'm':
                    case 'M':
                    money += 10;
                    cout << endl << "$10 has been added to your wallet!" << endl;
                    break;
                    default:
                    cout << "Q or M...You have kicked out of the store..." << endl;
                    system("PAUSE");
                    return 0;
                }
            }
            if(money - 10 < 0)
            {
                setcolor(7,black);
                cout << "You are almost out of money! Quickly hack the 1 digit pin (1-5) of the ATM!: ";
                cin >> pin;
                rpin = 1 + rand() % (5);
                if(pin < 1 || pin > 5)
                {
                    cout << "You should have entered a number from 1 - 5, you have been arrested." << endl;
                    system("PAUSE");
                    return 0;
                }

                if(pin == rpin)
                {
                    money += 20;
                    cout << "Success! You quickly get 20 dollars from the ATM." << endl;
                    break;
                }
                choice = 1 + rand() % (2);

                if(choice == 1)
                {
                    cout << "Wrong number, you run away from prying eyes." << endl;
                }
                else
                {
                    cout << "Wrong number, you have been arrested." << endl;
                    system("PAUSE");
                    return 0;
                }
            }
            money -= 10;
            if(money < 0)
            {
                setcolor(red,black);
                cout << "You are now in debt and you have to get more money..." << endl;
                setcolor(7,black);
                return 0;
            }

            setcolor(green,black);
            cout << "You now have $" << money << " in your account." << endl;
            setcolor(white,black);
            cout << "The lotto has started, may the odds ever be in your favor!" << endl;
            setcolor(7,black);

            int lotto_number[6];

            lotto_number[0] = 1 + rand() % (40);

            lotto_number[1] = 1 + rand() % (40);

            lotto_number[2] = 1 + rand() % (40);

            lotto_number[3] = 1 + rand() % (40);

            lotto_number[4] = 1 + rand() % (40);

            lotto_number[5] = 1 + rand() % (20);

            int choice[6];

            cout << "????? *" << endl;
            cout << "Enter your (?) choices 1 - 40." << endl;

            for(int choices = 0;choices < 5;choices++)
            {
                setcolor(color_number,black);
                cout << "Next: ";
                setcolor(color_number + 4,black);
                cin >> choice[choices];
                setcolor(7,black);
                color_number++;

                if(choice[choices] < 1 || choice[choices] > 40)
                {
                    cout << "Please enter a number from 1 - 40!" << endl;
                    choices--;
                }
            }

            for(;;)
            {
                setcolor(white,black);
                cout << "Now enter your powerball number." << endl;
                cout << "Please enter 1 - 20" << endl;
                setcolor(purple,black);
                cin >> choice[5];

                if(choice[5] < 1 || choice[5] > 20)
                {
                    cout << "Enter a number from 1 - 20!" << endl;
                }
                else
                {
                    break;
                }
            }

            color_number = 1 + rand() % (15);
            setcolor(white,black);
            cout << "The results are coming in..." << endl << "Here are the results!(Choice:Lotto Number) " << endl;
            setcolor(yellow,black);
            for(int relay = 0;relay < 5;relay++)
            {
                color_number = 1 + rand() % (15);
                cout << "Choice " << relay + 1 << ":\t";
                setcolor(color_number,black);
                color_number = 1 + rand() % (15);
                cout << choice[relay] << "\t:\t";
                setcolor(color_number,black);
                cout << lotto_number[relay];
                setcolor(yellow,black);
                cout << "\t Lotto number " << relay + 1 << endl;
            }

            for(int relay2 = 0;relay2 < 5;relay2++)
            {
                for(int relay3 = 0;relay3 < 5;relay3++)
                {
                    if(choice[relay2] == lotto_number[relay3])
                    {
                        setcolor(green,black);
                        cout << "You have gotten choice " << relay2 + 1 << " correct!" << endl;
                        number++;
                        lotto_number[relay3] = 0;
                        break;
                    }
                }
            }

            setcolor(white,black);

            cout << endl;
            setcolor(cyan,dark_magenta);
            cout << "Now for the powerball!" << endl;
            cout << "Your powerball is: " << choice[5] << endl;
            cout << "The powerball is: " << lotto_number[5] << endl;


            if(choice[5] == lotto_number[5])
            {
                setcolor(green,black);
                cout << "You have gotten the powerball right!" << endl;
                number2++;
            }

            setcolor(white,black);

            cout << endl <<  "Thanks you for playing the lotto, play again!" << endl;
            break;
            case 'n':
            case 'N':
            cout << "Bye bye!" << endl;
            system("PAUSE");
            return 0;
        }

        additive = number * number * number * 5;
        additive = additive + number2 * 1000;

        cout << "You have won: $";
        setcolor(green,dark_green);
        cout << additive;
        setcolor(white,black);
        cout << "!" << endl;
        money += additive;
    }
}
Last edited on
concor.h

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
#ifndef _EKU_CONCOL
#define _EKU_CONCOL

#ifndef _INC_WINDOWS
#include <windows.h>
#endif /*_INC_WINDOWS*/

bool textcolorprotect=true;
/*doesn't let textcolor be the same as backgroung color if true*/

enum concol
{
	black=0,
	dark_blue=1,
	dark_green=2,
	dark_aqua,dark_cyan=3,
	dark_red=4,
	dark_purple=5,dark_pink=5,dark_magenta=5,
	dark_yellow=6,
	dark_white=7,
	gray=8,
	blue=9,
	green=10,
	aqua=11,cyan=11,
	red=12,
	purple=13,pink=13,magenta=13,
	yellow=14,
	white=15
};

inline void setcolor(concol textcolor,concol backcolor);
inline void setcolor(int textcolor,int backcolor);
int textcolor();/*returns current text color*/
int backcolor();/*returns current background color*/

#define std_con_out GetStdHandle(STD_OUTPUT_HANDLE)

//-----------------------------------------------------------------------------

int textcolor()
{
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	GetConsoleScreenBufferInfo(std_con_out,&csbi);
	int a=csbi.wAttributes;
	return a%16;
}

int backcolor()
{
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	GetConsoleScreenBufferInfo(std_con_out,&csbi);
	int a=csbi.wAttributes;
	return (a/16)%16;
}

inline void setcolor(concol textcol,concol backcol)
{setcolor(int(textcol),int(backcol));}

inline void setcolor(int textcol,int backcol)
{
	if(textcolorprotect)
	{if((textcol%16)==(backcol%16))textcol++;}
	textcol%=16;backcol%=16;
	unsigned short wAttributes= ((unsigned)backcol<<4)|(unsigned)textcol;
	SetConsoleTextAttribute(std_con_out, wAttributes);
}

#if defined(_INC_OSTREAM)||defined(_IOSTREAM_)
ostream& operator<<(ostream& os,concol c)
{os.flush();setcolor(c,backcolor());return os;}
#endif

#if defined(_INC_ISTREAM)||defined(_IOSTREAM_)
istream& operator>>(istream& is,concol c)
{cout.flush();setcolor(c,backcolor());return is;}
#endif

#endif /*_EKU_CONCOL*/
bump
 
main.c:30:1: error: function too long, compiler confused

Last edited on
excuse me? oh this is c++ too.

What compiler are you using?
He was just making a comment about ridiculous function length.
Well then make is smaller.
closed account (zb0S216C)
@greenleaf800073: It's your code; you make it smaller.

Wazzak
@Framework: he meant this:


is

is

is

is
Last edited on
lol, well, this is the place for improvements isn't it? that means you find a way to help me
A bit demanding, aren't you?
lol, well, this is the place for improvements isn't it? that means you find a way to help me


It is a place for improvement. Unfortunately, you don't improve by having people do stuff for you.

Asking for comments and then say "Derp. You do it." whenever someone does so.. that could be improved upon.
What are we talking about again...


Just comments on how it works please...
Topic archived. No new replies allowed.