i was playing the game a little more. remember my formula for winnings. well i found a glitch that has to do with the bet, numbers to pick, and my formula. ya see, you can enter up to 99 for amoun of numbers to pick, and you can bet more than you have, and since you cant lose credits, the program enters thos numbers into the formula. then you type 20 random numbers (aka 1-20), and watch your credits gro exponantoly. we need a way to make sure this dosent happen. also, i revised the printf statments a little mor to make it look and feel better.
#include <stdio.h> #include <stdlib.h> #include <time.h> int main (void) { char response[10]; int n=0; int n2=0; int picknum=0; int picks[20]; int randomnumbers[20]; int correct=0; float bet=0; float winnings=100;
srand(time(NULL)); //Seed the random nubmer generator do{ n=0; n2=0; correct=0; printf("How many numbers do you want to pick?\n \n \t - "); scanf("%d", &picknum); if(picknum>20) picknum=20; if(picknum<1) picknum=1; printf("What is your bet? You have %f credits\n \n \t - ", winnings); scanf("%f", &bet); printf("enter the #'s (1-80) you want to pick. type your #, then press enter.\n repeat as nessissary.\n \n");
while(n<picknum) { scanf("%d", picks+n); if(picks[n]<80&&picks[n]>0) n++; } n=0; while(n<20) { int test=rand()%80+1; while(n2<n) //Check every value to make sure it isn't a duplicate { if(test==randomnumbers[n2]) break; n2++; } if(n2==n)//If the while loop didn't break, they would be equal { randomnumbers[n]=test; n++; } n2=0; } n=0; n2=0; while(n<picknum) { while(n2<20) { if(picks[n]==randomnumbers[n2]) correct++; n2++; } n2=0; n++; }
//Don't know the scoring formula. Paste it here. winnings+=((picknum*bet*correct)/10); printf("You had %i correct. Your current number of credits is %f.\n \nContinue?(Y/N)\n \n \t - ", correct, winnings); scanf("%s", response); if(response[0]=='N' || response[0]=='n') break; }while(winnings>0); printf("You have won %i credits\n \n", winnings); }
matt wuz here
|