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;
}
|