NEED HELP! =(

Pages: 12
I am new to programming, I am shocked I got this far with this program. However, i need help because when i run the program, it asks for the users input but it will not print out the slot machine and the winnings for the user. Also before i added a few things to the PrintSlot functions and it was actually printing, I was not getting the correct value for the users winnings and total. The int numbers would also be a negative number and the program would always repeat the same number the more i continued to add bets. I have no clue where the problem is, i am sure there is a lot wrong with the code but like i said i am new and my professor will not look over it. I NEED HELP, PLEASE
Thank you

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
 #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//DECLARATIONS
void GetStartAmount (int* StartA);
int GetBet (int* bet, int StartA);
void randSlotNum(int* WinT, int* s1, int* s2, int* s3);
void Calculations(int* Winnings, int* NewAm, int StartA, int bet, int WinT);
void PrintSlot (int StartA, int bet, int NewAm, int s1, int s2, int s3, int WinT, int Winnings);
int main ()
{
    //VARIABLES
    int StartA;
    int bet;
    int NewAm;
    int s1;
    int s2;
    int s3;
    int WinT;
    int Winnings;
        printf("COP 2220 Project 3 - absslsdlasla\n\n");
        printf("Let's play Crazy Eights!\n\n");
    GetStartAmount (&StartA);
    Calculations(&Winnings, &NewAm, StartA, bet, WinT);
    PrintSlot (StartA, bet, NewAm, s1, s2, s3, WinT, Winnings);


    return 0;

}

    void GetStartAmount (int* StartA)
    {
         printf("How many dollars do you want to start with (0 to quit)? ");
         scanf("%d", StartA);
         do{
            if(* StartA == 0)
            {
                printf("What's the matter? You scared punk?\n\n");
                exit (1);
            }
            if(*StartA < 1)
            {
                printf("ERROR: Enter at least one dollar or zero to cash out.\n\n");
                exit(2);
            }
         }while(*StartA <= 1);
        return;
    }


    int GetBet (int* bet, int StartA)
    {
        do{
            printf("How many dollars do you want to bet (enter 0 to cash out)? ");
            scanf("%d", &bet);
            if(*bet == 0)
            {
                printf("You're no fun.\n\n");
                exit(3);
            }
            if(*bet > StartA)
            {
                printf("Sorry, you don't have that much left.\n\n");
            }
        }while(*bet >= StartA);
        return *bet;
    }

    void randSlotNum(int* WinT, int* s1, int* s2, int* s3)
    {
        srand(time(NULL));
        *s1 = rand()%8+1;
        *s2 = rand()%8+1;
        *s3 = rand()%8+1;

        if(*s1 == 8 && *s2 == 8 && *s3 == 8)
        {
            *WinT = 1;
        }
        else if(*s1 == *s2 && *s2 == *s3)
        {
            *WinT = 2;
        }
        else if(*s1 == *s2 || *s2 == *s3 || *s1 == *s3)
        {
            *WinT = 3;
        }
        else if(*s1 == 8 || *s2 == 8 || *s3 == 8)
        {
            *WinT = 4;
        }
        else
        {
            *WinT = 5;
        }
        return;
    }


    void Calculations(int* Winnings, int* NewAm,int StartA, int bet, int WinT)
    {
        switch(WinT)
        {
        case 1:
            *Winnings = bet * 80;
            break;
        case 2:
            *Winnings = bet * 25;
            break;
        case 3:
            *Winnings = bet * 2;
            break;
        case 4:
            *Winnings = bet;
            break;
        case 5:
            *Winnings = 0;
            break;
        default:
            break;
        }

        return;
    }


    void PrintSlot (int StartA, int bet, int NewAm, int s1,
                    int s2, int s3, int WinT, int Winnings)
    {
        while(GetBet(&bet, StartA))
        {
            randSlotNum(&WinT, &s1, &s2, &s3);

            printf("       _____      \n");
            printf("_____/ 888 \\_____\n");
            printf("/  Crazy Eights   \\ \n");
            printf("|=================|  __\n");
            printf("| 888     80x Bet | (  )\n");
            printf("| Match 3 25x Bet |  ||\n");
            printf("| Match 2  2x Bet |  ||\n");
            printf("| Eight    1x Bet |  ||\n");
            printf("|-----+-----+-----|  ||\n");
            printf("| %2d  | %2d  | %2d  |  ||\n", s1, s2, s3);
            printf("|-----+-----+-----|  ||\n");
            if(s1==s2==s3==8 || s1==s2==s3 || s1==8 || s2==8 || s3==8 || s1==s2 || s2==s3 || s1==s3)
    {
        printf("| WIN!  WIN!  WIN! |__||\n");
    }
    else
    {
        printf("|       SORRY      |__||\n");
    }
    if(s1==s2==s3 == 8)
    {
        printf("|     JACKPOT!     |---'\n");
    }
    else if(s1==s2==s3)
    {
        printf("|     Match 3!     |---'\n");
    }
    else if(s1==s2 || s2==s3 ||s1==s3)
    {
        printf("|     Match 2!     |---'\n");
    }
    else if(s1==8 || s2==8 || s3==8)
    {
        printf("|   Crazy eight    |---'\n");
    }
    else
    {
        printf("|    Try Again     |---'\n");
    }
            printf("|     _______     |\n");
            printf("|____/ o o   \\____|\n");
            printf("\\     o oo o      /\n");
            printf(" \\_______________/\n");
            printf("  U             U\n\n");

            if(WinT == 1)
            {
                printf("JACKPOT! You win $%d\n\n", Winnings);
            }
            else if(WinT >= 2 && WinT <=4)
            {
                printf(" You won! Your total is $%d\n\n", Winnings);
            }
            else
            {
                printf("Sorry, no winning combination.\n\n");
            }

        NewAm = StartA + (Winnings - bet);
        printf("Your current total is $%d\n", NewAm);
        }
        return;
    }
Last edited on
closed account (48T7M4Gy)
You forgot to tell us your code doesn't compile either:

1, line 71 needs to return an integer or change it to void.
closed account (48T7M4Gy)
Once again this is a case where it is better to cut, paste and comment out the functions you think are a problem and just testing that.

To wade through this pile is probably why your professor won't even look.

Just make a copy a new short main() and comment out all the functions you are not testing.
Last edited on
I have made some changes to it. it is compiling for me on codeblocks. I honestly am pretty much clueless, my professor will not look at the code because he expects us all to understand this so he wont look at anybody's code. Also i can not use short main, he wants all of it to be done in int main()
Last edited on
closed account (48T7M4Gy)
Yeah I understand your problem and I'd like to help but you need to narrow down the place where it is occurring. Debugging can be fun believe it or not.

Also i can not use short main, he wants all of it to be done in int main()

Take a deep breath, that's not what I mean. You don't submit the testing (shortened) version. Just make a test program, fix the problem by concentrating on that and once that bit is fixed move back to the full version.

Try it, it works! If you have any problems with that feel free to ask and it will make it that much easier and quicker to help out.
closed account (48T7M4Gy)
PS HAve you fixed the error I told you about above? Your program won't run until t is fixed. :)
I've added return *bet; to it, if that is what you mean't. I honestly barely have clue what i am doing.
Also, the place where the problem is occurring is in the printSlots funtions, everything was running smoothly before i started to tinker with it because i have to add print the users winnings and total at the end. so i added that and it started to not print the slots at all. i just tired deleting it and it didnt work. still isnt printing it all out.
closed account (48T7M4Gy)
OK I see you made the change
closed account (48T7M4Gy)
So what you do is see whether it is even getting to the function.

To check that put a line in at the start of the function

printf("GOT THIS FAR\n"); and see what happens.
the printf("GOT THIS FAR\n"); printed. however it printed right after it asks you how many dollars would you like to start with.
How many dollars do you want to start with (0 to quit)?
GOT THIS FAR
How many dollars do you want to bet (enter 0 to cash out)?



this was what it printed out
closed account (48T7M4Gy)
i started to tinker

You're not kidding you tinkered. You need to go through and fix up all the pointers you created because that's where your problem is.

For instance StartA is declared as an integer and you are using it elsewhere as an integer. And that's just the beginnining. :(

It's not the end of the world but you'll just have to unravel it, function by function.
I've realized that but the problem is i have not been taught how to do that. i know i sound stupid saying that but i dont get what you mean by that.
kjl
Last edited on
I wouldn't blame your professor. You've built this application up too quickly without testing components as you go and now you're in a situation where it doesn't work.
closed account (48T7M4Gy)
My god i've just realized how bad my professor is at explain this stuff.


I understand but let's forget about the prof. I am having a close look at your program and I can show you what I have so far if you like.

I don't think it's fair to you to re-write it for you but one things is loud and clear ... you should be using <iostream> functionality which means cin and cout.

It is so much easier instead of the rubbish scanf and printf and that is the reason you and your friends are having so much trouble. They are old-fashioned crap and shouldn't be taught to beginners.

Let me know.

PS I'll post it anyway
Last edited on
closed account (48T7M4Gy)
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
#include <iostream>

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

using namespace std;

//DECLARATIONS
void GetStartAmount(int&);
int GetBet(const int StartA);
//void randSlotNum(int* WinT, int* s1, int* s2, int* s3);
//void Calculations(int* Winnings, int* NewAm, int StartA, int bet, int WinT);
//void PrintSlot(int StartA, int bet, int NewAm, int s1, int s2, int s3, int WinT, int Winnings);

int main()
{
	//VARIABLES
	int StartA = 0;
	int bet = 0;
	int NewAm = 0;
	int s1 = 0;
	int s2 = 0;
	int s3 = 0;
	int WinT = 0;
	int Winnings = 0;

	cout << "COP 2220 Project 3 - absslsdlasla" << endl;
	cout << "Let's play Crazy Eights!" << endl;

	GetStartAmount(StartA);
	bet = GetBet(StartA);

	//Calculations(&Winnings, &NewAm, StartA, bet, WinT);
	//PrintSlot(StartA, bet, NewAm, s1, s2, s3, WinT, Winnings);

	return 0;

}

void GetStartAmount(int& start)
{
	cout << "How many dollars do you want to start with (0 to quit)? ";
	cin >> start;

	while (start <= 1)
	{
		cout << "What's the matter? You scared punk?" << endl;
		cout << "ERROR: Enter at least one dollar or zero to cash out." << endl;

		cin >> start;
	}
	return;
}

int GetBet(const int start)
{
	int aBet;
	cout << "How many dollars do you want to bet (enter 0 to cash out)? ";
	cin >> aBet;

	while (aBet >= start)
	{
		if (aBet == 0)
			printf("You're no fun.\n\n");
		
		if (aBet > start)
			cout << "Sorry, you don't have that much left." << endl;
		cin >> aBet;
	}

	return aBet;
}
	return;
}
Last edited on
The thing is that he will not accept that because we dont use #include <iostream>
also code blocks wont compile it but thank you so much for the help.
i am trying a new way and seeing if it will work, if not i think im just gonna turn in something and get as much credit as i can.
when i am done with this one, will it be cool if i post it and tell me if there are any mistakes?
closed account (48T7M4Gy)
Well that's OK - what you have to watch is whether any statement refers to an address, a pointer or the actual variable itself. The temptation is if it doesn't work put an &, or a * or take them off almost at random. But the only way is to write down that snippet exactly bit by bit to debug.

BTW codeblocks will compile iostream, thousands and thousands of people all over the planet, do it every minute of the day - I feel sorry for the treatment you are getting but it's more important to look at the future and just play the game with a bad teacher - you won't be there forever - eventually you leave them behind. :)

No problem, post when you are ready there's always somebody who'll help regardless of my movements. Try and post here, not for my benefit but so people can see the history and see that you're prepared to give things a go.

Cheers
Pages: 12