Lotto Simulation Problem

I think I got pretty much of the code, but I need help on the bottom. How do i define user and lottery.. Confused!! Also code is confusing so help also...

//Declarations
#include <iostream>
#include <cstdlib>
#include <ctime>

const int lotteryDigits = 10;
const int SIZE = 5;
const int Power = 1;

int generateLottery(int[], int, int);
int powerBall(int[], int);
int userInput(int[], int);
int count1= 0;
int matchCounter(int[], int[], int);
void displayNumbers(int[], int[]);
void displayhotball (int[], int[]);
void winnerOrLoser(int);
bool matches = true;



using namespace std;

int main()
{
int lottery[5] = {0, 0, 0, 0, 0};
int user[5] = {0, 0, 0, 0, 0};
int ball[1] = {0};
int matches = 0;

generateLottery(lottery, SIZE, lotteryDigits);

userInput(user, SIZE);

matchCounter(lottery, user, matches);

displayNumbers(lottery, user);

displayhotball(ball, user);

winnerOrLoser(matches);

system ("pause");
return 0;
}
//Randomly generates winning lottery numbers and power numer

int generateLottery(int lottery[], int, int)
{
unsigned seed = time(0);
srand(seed);

for (int y=0; y<SIZE; y++)
{
lottery[y] = rand() % lotteryDigits;
}

return lottery[0], lottery[1], lottery[2], lottery[3], lottery[4];
}

int powerBall(int ball[], int)
{
unsigned seed = time(0);
srand(seed);

int x;
for (x=0; x<Power; x++);
{
ball[x]= rand() % SIZE;
}

return ball[0];
}
//Reads user lottery number choices

int userInput(int user[], int)
{
for (int count1=0; count1<SIZE; count1++)
{

cout<<"Enter a digit between 0 and 9:--->";
cin>> user[count1];

while (user[count1]<0 || user[count1]>9)
{
cout<<" Error! Entry must be between 0 and 9--->";
cin>> user[count1];
}
}

for( int count1=0; count1<Power; count1++)
{
cout<<"Enter a hot power number between 0 and 5--->";
cin>> user[count1];

while (user[count1]<0 || user[count1]>5)
{
cout<<" Error! Entry must be between 0 and 5--->";
cin>> user[count1];
}
}
return 0;
}// end userInput

// Counts the number of matches

int matchCounter(int lotto [], int input[], int)
{
int match = 0;

for (int x = 0; x < SIZE; ++x)
{
if (lotto[x] == input[x])
match = match + 1;
}

return match;
}


//Displays the winning numbers and the user's number

void displayNumbers(int lottery[], int user[])
{
cout << "\nThe winning lottery numbers are: " << lottery[0] <<" "<< lottery[1]<<" "<< lottery[2]<<" "<<lottery[3]<<" "<<lottery[4]<< endl;
cout << "Your lottery numbers are: " << user[0] << " " << user[1] << " " << user[2] << " " << user[3] << " " << user[4] << endl;
}
//Displays Power Number
void displayhotball(int ball[], int user[])
{
cout << "\nHot Winning Number:" << ball[0]<< endl;
cout<< "Your hot number is:" << user[0]<< endl;
}

//Determines matches
void winnerOrLoser(int matches)
{
for (matches = 0; matches < SIZE; matches++)
{
while (matches < SIZE)
{
if (user[count1] != lottery[count1])
matches = false;
count1++;
}
cout << "You matched " << matches << " numbers";

if (matches != SIZE)
cout << "\nSorry--you lose. Better luck next time.\n";
else if (matches == Power)
cout << "\nCongratulations--you win $4!!!!\n";
else if (matches== 1&&Power)
cout<<"\nYou win $4\n";
else if (matches == 2)
cout<<"\nYou win $7\n";
else if (matches == 2&&Power)
cout<<"\nYou win $7\n";
else if (matches == 3)
cout<<"\nYou win $7\n";
else if (matches == 3&&Power)
cout<<"\nYou win $100\n";
else if (matches == 4)
cout<<"\nYou win $100\n";
else if (matches == 4&&Power)
cout<<"\nYou win $10000\n";
else if (matches == 5)
cout<<"\nYou win $100000\n";
else ( matches == SIZE);
cout<< "\nYou win $2,000,000\n";
}
Last edited on
Please use code tags. Here is a functioning program. Extract info from it.

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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;

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

    for(;;)
    {
        additive = 0;
        cout << "Welcome to the lotto! Entering will deduct $5 from your bank account." << endl;
        cout << "You currently have: $" << money << endl;
        cout << "Would you like to proceed? (Y/N): ";
        cin >> input;
        cout << endl;

        switch(input)
        {
            case 'y':
            case 'Y':
            srand((unsigned)time(0));
            if(money == 0)
            {
                cout << "Warning, you have 0 dollars left. Quit or get money? (Q/M): ";
                cin >> input2;
                switch(input2)
                {
                    case 'q':
                    case 'Q':
                    cout << endl << "Thank you, come again!" << endl;
                    return 0;
                    case 'm':
                    case 'M':
                    money += 50;
                    cout << endl << "$50 has been added to your wallet!" << endl;
                    break;
                    default:
                    cout << "Q or M...You have kicked out of the store..." << endl;
                    return 0;
                }
            }

            if(money < 0)
            {
                cout << "You are now in debt and you have to get more money..." << endl;
                return 0;
            }
            money -= 5;

            cout << "You now have $" << money << " in your account." << endl;
            cout << "The lotto has started, may the odds ever be in your favor!" << endl;

            int lotto_number[6];

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

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

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

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

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

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

            int choice[6];

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

            for(int choices = 0;choices < 5;choices++)
            {
                cout << "Next: ";
                cin >> choice[choices];

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

            for(;;)
            {
                cout << "Now enter your powerball number." << endl;
                cout << "Please enter 1 - 10" << endl;
                cin >> choice[5];

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

            cout << "Remember, you have to get every number right, in ORDER!" << endl;
            cout << "and the results are coming in..." << endl << "Here are your choices: " << endl;

            for(int relay = 0;relay < 5;relay++)
            {
                cout << "Number " << relay + 1 << ":" << choice[relay] << endl;
            }

            cout << "Now for the real results: " << endl << endl;

            for(int relay2 = 0;relay2 < 5;relay2++)
            {
                cout << "Lotto number " << relay2 + 1 << ":" << lotto_number[relay2] << endl;
            }

            cout << endl;

            for(int relay3 = 0;relay3 < 5;relay3++)
            {

                if(choice[relay3] == lotto_number[relay3])
                {
                    cout << "You have gotten choice " << relay3 + 1 << " correct!" << endl;
                    number++;
                }
            }

            cout << endl;

            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])
            {
                cout << "You have gotten the powerball right!" << endl;
                number2++;
            }

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

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

        cout << "You have won: $" << additive << "!" << endl;
        money += additive;
    }
}
What are code tags?
ckw77 wrote:
What are code tags?

They're formatting tags so your code highlights syntax correctly. When you post, you can use the <> button in the formatting box on the right.

I guess a better answer is this...

ckw77 wrote:
What are code tags?

The difference between getting your problem solved or not.
Still not understanding, but I used the formatting key to edit the code above and that what I got. Can somebody just try running the code, and telling me what erroes I need to fix to get the program to run correctly.
First, Use code tags and indent.


...


...


...


...
Fixed some more:

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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;

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

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

        switch(input)
        {
            case 'y':
            case 'Y':
            srand((unsigned)time(0));
            if(money == 0)
            {
                cout << "Warning, you have 0 dollars left. Quit or get money? (Q/M): ";
                cin >> input2;
                switch(input2)
                {
                    case 'q':
                    case 'Q':
                    cout << endl << "Thank you, come again!" << endl;
                    return 0;
                    case 'm':
                    case 'M':
                    money += 50;
                    cout << endl << "$50 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 < 0)
            {
                cout << "You are now in debt and you have to get more money..." << endl;
                return 0;
            }
            money -= 5;

            cout << "You now have $" << money << " in your account." << endl;
            cout << "The lotto has started, may the odds ever be in your favor!" << endl;

            int lotto_number[6];

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

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

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

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

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

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

            int choice[6];

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

            for(int choices = 0;choices < 5;choices++)
            {
                cout << "Next: ";
                cin >> choice[choices];

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

            for(;;)
            {
                cout << "Now enter your powerball number." << endl;
                cout << "Please enter 1 - 10" << endl;
                cin >> choice[5];

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

            cout << "The results are coming in..." << endl << "Here are the results!(Choice:Lotto Number) " << endl;

            for(int relay = 0;relay < 5;relay++)
            {
                cout << "Choice " << relay + 1 << ":\t" << choice[relay] << "\t:\t";
                cout << lotto_number[relay] << "\t Lotto number " << relay + 1 << endl;
            }

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

            cout << endl;

            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])
            {
                cout << "You have gotten the powerball right!" << endl;
                number2++;
            }

            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 * 5;
        additive = additive + number2 * 1000;

        cout << "You have won: $" << additive << "!" << endl;
        money += additive;
    }
}
I tried running your code and got errors about user and lottery not being declared, as well as a missing } at the end of your last function:

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
//Determines matches
void winnerOrLoser(int matches)
{
    for (matches = 0; matches < SIZE; matches++)
    {
        while (matches < SIZE) //matches never changes in this loop.
        {
            //error: 'user' was not declared in this scope
            //error: 'lottery' was not declared in this scope
            if (user[count1] != lottery[count1])
                matches = false;
            count1++;
        }
        cout << "You matched " << matches << " numbers";

        if (matches != SIZE)
            cout << "\nSorry--you lose. Better luck next time.\n";
        else if (matches == Power)
            cout << "\nCongratulations--you win $4!!!!\n";
        else if (matches== 1&&Power)
            cout<<"\nYou win $4\n";
        else if (matches == 2)
            cout<<"\nYou win $7\n";
        else if (matches == 2&&Power)
            cout<<"\nYou win $7\n";
        else if (matches == 3)
            cout<<"\nYou win $7\n";
        else if (matches == 3&&Power)
            cout<<"\nYou win $100\n";
        else if (matches == 4)
            cout<<"\nYou win $100\n";
        else if (matches == 4&&Power)
            cout<<"\nYou win $10000\n";
        else if (matches == 5)
            cout<<"\nYou win $100000\n";
        else ( matches == SIZE);
            cout<< "\nYou win $2,000,000\n";
    }
    //error: expected '}' at end of input 


To fix the user and lottery problem, add parameters to the function for user[] and lottery[]:

void winnerOrLoser(int matches, int user[], int lottery[])

(Remember to adjust your function prototype accordingly)

Finally, add a } at the end of your winnerOrLoser function, and it should work (my output, notice the "ctrl C" [^C] at the end, you have an infinite loop in your winnerOrLoser function):

Enter a digit between 0 and 9:--->1
Enter a digit between 0 and 9:--->2
Enter a digit between 0 and 9:--->3
Enter a digit between 0 and 9:--->4
Enter a digit between 0 and 9:--->5
Enter a hot power number between 0 and 5--->6
 Error! Entry must be between 0 and 5--->-1
 Error! Entry must be between 0 and 5--->5

The winning lottery numbers are: 7 7 8 3 9
Your lottery numbers are: 5 2 3 4 5

Hot Winning Number:0
Your hot number is:5
^C


Once you get that going, let us know as there are a few things (related to the design) that I noticed about your code that should be fixed.

Edit:

About code tags

http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
UPDATE: 2/14/13: Fixed some minor run time bugs and added extra feature

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
#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 += 50;
                    cout << endl << "$50 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;
                }
                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() % (20);

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

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

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

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

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

            int choice[6];

            cout << "????? *" << endl;
            cout << "Enter your (?) choices 1 - 20." << 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] > 20)
                {
                    cout << "Please enter a number from 1 - 20!" << endl;
                    choices--;
                }
            }

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

                if(choice[5] < 1 || choice[5] > 10)
                {
                    cout << "Enter a number from 1 - 10!" << 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
Comment on mine?


*This is a vague response to a vague question.* Are you asking if I am commenting on your code or are you asking me to comment on your code?

Fixed another little bug:


What was the bug? Or do you expect us to read all 160 lines of each post and figure it out? *Tip* there's an edit button. Use it to edit your old posts and fix bugs instead of flooding the page (mah scroll wheel is begging of you). And make sure you make a mention of what you changed and why.
Last edited on
(mah scroll wheel is begging of you)


(Can't you press it down to engage fast scrolling?)

But no one notices editing...
But no one notices editing...


Which is why you make a post at the same time saying: Previous code edited to fix: "Insert something here."
If you edit previous posts there's no history, so anyone coming late to the conversation can a) not tell what's already been fixed, and b) not learn anything from seeing how someone else fixed their problems.

I know it generates more bandwidth, but it is useful to see the evolution of a solution.

Jim
I know it generates more bandwidth, but it is useful to see the evolution of a solution.


On the other hand if it is a simple bug fix, there isn't any evolution, there is only a minor correction, and correcting it in the original post is probably better than reposting umpteen lines of unchanged code and tempting people coming late to the thread to respond with a fix for said bug without reading the entire thread, thereby giving everyone a higher noise to signal ratio.

Just mentioning what the fix is solves both problems to some degree.
I guess it depends on the thread content.

I tend to refer to specific lines in the posted problem code, so any editing that goes on will render my comments confusing, at best, and probably useless. No witty remarks, thankyouverymuch ;-)

Jim
Uhhhh ok,

Previous code to fix = ADDED FUNKY COLORS!

#include "concor.h"

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*/
Topic archived. No new replies allowed.