All pastes #772002 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-13 13:43 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define Cherry 0
#define Seven 1
#define X 2
#define Jac 3
#define Apple 4

int weee(void);

int main (void)
{
		FILE *fp;
		int torun; // Number of times to run
		int ran = 0; // Number of times ran counter
 		int random; // To store the random number
		char cher[] = "Cherry";
		char seven = '7';
		char x[] = "XXX";
		char jac[] = "Jac";
		char appl[] = "Apple";
		int credit = 0;
		int spin1, spin2, spin3;
		int money = 0;

		srand (time(0));
		fp = fopen ("output2.txt", "a");

		printf("How many times would you like to play?: ");
		fflush(stdin);
                scanf("%d", &torun);

		while (ran < torun) {
				credit = 0;
				
				
				spin1 = weee();
				
				switch (spin1) {
						case 0: case 1: case 2: case 3: case 4:	spin1 = Apple; credit += 1; break;
						case 5: case 6: case 7: case 8: spin1 = X; credit += 4;
						case 9: case 10: case 11: case 12: case 13: case 14: spin1 = Jac; credit += 16; break;
						case 15: case 16: case 17: case 18: spin1 = Seven; credit += 25; break;
						case 19: case 20:  spin1 = Cherry; credit += 9; break;
				}
				
				spin2 = weee();

				switch (spin2) {
						case 0:	case 1: case 2: case 3: case 4: spin2 = Apple; credit += 1; break;
						case 5: case 6: case 7: case 8: case 9: case 10: spin2 = X; credit += 4; break;
						case 11: case 12: case 13: case 14: case 15: spin2 = Jac; credit += 16; break;
						case 16: case 17:spin2 = Seven; credit += 25; break;
						case 18: case 19: case 20: spin2 = Cherry; credit += 9; break;
				}

				spin3 = weee();

				switch (spin3) {
						case 0:	case 1: case 2: case 3: case 4: spin3 = Apple; credit += 1; break;
						case 5: case 6: case 7: case 8: case 9: spin3 = X; credit += 4; break;
						case 10: case 11: case 12: case 13: case 14: spin3 = Jac; credit += 16; break;
						case 15: case 16: case 17: spin3 = Seven; credit += 25; break;
						case 18: case 19: case 20: spin3 = Cherry; credit += 9; break;
				}

				if (spin1 == Apple)
						fprintf(fp,"%s ", appl);
				else if (spin1 == X)
						fprintf(fp,"%s ", x);
				else if (spin1 == Jac)
						fprintf(fp,"%s ", jac);
				else if (spin1 == Seven)
						fprintf(fp,"%c ", seven);
				else if (spin1 == Cherry)
						fprintf(fp,"%s ", cher);
				else
						;
				
				if (spin2 == Apple)
						fprintf(fp,"%s ", appl);
				else if (spin2 == X)
						fprintf(fp,"%s ", x);
				else if (spin2 == Jac)
						fprintf(fp,"%s ", jac);
				else if (spin2 == Seven)
						fprintf(fp,"%c ", seven);
				else if (spin2 == Cherry)
						fprintf(fp,"%s ", cher);
				else
						;
				
				if (spin3 == Apple)
						fprintf(fp,"%s\n", appl);
				else if (spin3 == X)
						fprintf(fp,"%s\n", x);
				else if (spin3 == Jac)
						fprintf(fp,"%s\n", jac);
				else if (spin3 == Seven)
						fprintf(fp,"%c\n", seven);
				else if (spin3 == Cherry)
						fprintf(fp,"%s\n", cher);
				else
						;

			
				if (credit == 3) {
						fprintf(fp,"\nApples!\n\n");
						money += 10;
				}
				else if (credit == 12) {
						fprintf(fp,"\nX's!\n\n");
						money += 1;
				}
				else if (credit == 27) {
						fprintf(fp,"\nCherries!\n\n");
					 money += 25;
				}
				else if (credit == 48) {
						fprintf(fp,"\nJacks!\n\n");
						money += 5;
				}
				else if (credit == 75) {
						fprintf(fp,"\n7's!\n\n");
						money += 50;
				}
				ran++;
}

fprintf(fp,"You won %d dollars!\n", money);
fclose(fp);
fflush(stdin);
getchar();
}

int weee(void)
{
		int temp;
		temp = rand() % 21;
		return temp;
}