📄 rand.c
字号:
//Hou Ben Ng//Oct 14, 2006//CS200/* This program is about making up a random number in the beginning, and then hiden from the player to plays a game on DEAL or NO DEAL. first is callin the user to choose between the averge amount from all the suitcase left that after the one he/she has picked. If the player choose deal, he/she will bring those money home, if not, he/she will continue playing the game. It will has three chance on picking and ask player deal or not.*/#include <stdio.h>//#include <iostream>int rand(void);void srand(int seed);unsigned int next;main(int argc, char** argv){ int i,j,seed; //some number for the math part in the function int s[i]; //value in each suitcases int u_i; //user to choose the suitcase for hidden int chtot; //total amount int chh; //chh is the total amount of all the suitcases and temp data save int ch0,ch1,ch2,ch3; //ch1 is the first choose value that averge on all suitcases (9 sucitases) //ch1 is the first choose value that averge on all suitcases (8 sucitases) //ch2 is the first choose value that averge on all suitcases (7 sucitases) //ch3 is the first choose value that averge on all suitcases (6 sucitases) char p0,p1,p2,p3; //the suitcase number char c; //input on choosing DEAL or NO DEAL char r_c2; //second user response on the suitcase he/she have choose char temp; //use to get rape of the \n in input buffer /* not sure what's gonig on here, but it works*/ if (argc != 2) { fprintf(stderr,"Give me two number between 1 to 99 in"); fprintf(stderr,"Please input again,thanks\n"); return(0); } seed = atoi(argv[1]); srand(seed); for (i=0; i < 10; i++) { printf("%d : ***\n", i + 1, rand()); s[i] = rand(); } p0 = p1 = p2 = p3 = 0; //initiallize the number //choose a suitcase from the list printf("\nNow is time for you to choose a suitcase, this"); printf("\nsuitcase will be save to the end of the game"); printf("\nif you are choosing NO DEAL till the end"); printf("\nPlease choose one of the suitcases from 1 to 10: "); u_i = getchar(); //get the number of suitcase temp = getchar(); //eat the \n in here p0 = u_i; //use for showing the numbers had pick //asking right or wrong, allow to choose again printf("\n**NOTE: No. %d is the one you want to choose?", p0 - 48 ); printf("\nYes(y) to continue or No(n) to choose again: "); r_c2 = getchar(); //get the response temp = getchar(); //eat the \n in here while ( r_c2 == 'n' || r_c2 == 'N') { printf("\nPlease choose again:"); u_i = getchar(); //get the number of suitcase temp = getchar(); //eat the \n in here p0 = u_i; printf("\nIs this the right one(Y/N)"); r_c2 = getchar(); //check it again with user temp = getchar(); //eat the \n in here } /* replace the value with the suitcase number */ {; if ( u_i == '1') {ch0 = s[0];} else if (u_i == '2') {ch0 = s[1];} else if (u_i == '3') {ch0 = s[2];} else if (u_i == '4') {ch0 = s[3];} else if (u_i == '5') {ch0 = s[4];} else if (u_i == '6') {ch0 = s[5];} else if (u_i == '7') {ch0 = s[6];} else if (u_i == '8') {ch0 = s[7];} else if (u_i == '9') {ch0 = s[8];} else {ch0 = s[9];} } printf("\n***LET'S BEGIN OUR GAME!!***"); printf("\nOk~ now we have 9 suitcases left, and you have"); printf("\nTHREE time to choose other suitcases for eliminated the suitcauses in here."); printf("\nWe will show you the average on the remain suitcause, you can pick the average"); printf("\nhere or the value of suitcase you got by DEAL or NO DEAL"); printf("\n"); printf("\n *****If you understand pass ENTER to continue*****"); temp = getchar(); //eat the \n in here /* Let the game begin~!! HOHO~~~ */ chh = ch0 = ch1 = ch2 = ch3 = 0; //initiallize them to be zero for (i=0; i<10; ++i) { chtot = chtot + s[i]; } ch0 = chtot-ch0; //find out the total remain value chh = ch0%6498; //average on the remain chh = chh/9; printf("\n"); printf("\nOur suitcases average value is %3.0d right now", chh); printf("\nDo you want the AVERAGE instead of your suitcase's value?"); printf("\nDEAL or NO DEAL (d/n): "); c = getchar(); printf("\n"); while( c != 'D' && c != 'd' && c != 'N' && c != 'n') { temp = getchar(); //eat the \n from the input above printf("Sorry, please type in D or N for"); printf("DEAL or NO DEAL: "); c = getchar(); printf("\n"); } if ( c == 'D' || c == 'd') { printf("\nCongratulation!! You have earn %3.0d on today!!", chh); printf("\nThank you for coming...\n"); return(0); } /* First chose */ temp = getchar(); printf("\nWell, you have choose NO DEAL let's eliminate a suitcase from here"); printf("\nNOTE: You can't change once you chose, so think hard!!"); printf("\nEliminate: %d", p0 - 48); printf("\nYou choose: "); p1 = getchar(); temp = getchar(); /* replace the value with the suitcase number */ { if ( p1 == '1') { ch1 = s[0];} else if (p1 == '2') { ch1 = s[1];} else if (p1 == '3') { ch1 = s[2];} else if (p1 == '4') { ch1 = s[3];} else if (p1 == '5') { ch1 = s[4];} else if (p1 == '6') { ch1 = s[5];} else if (p1 == '7') { ch1 = s[6];} else if (p1 == '8') { ch1 = s[7];} else if (p1 == '9') { ch1 = s[8];} else { ch1 = s[9];} } ch1 = ch0 - ch1; chh = ch1%6498; chh = chh/8; printf("\n"); printf("\nOur suitcases average value is %3.0d right now", chh); printf("\nDo you want the AVERAGE instead of your suitcase's value?"); printf("\nDEAL or NO DEAL (d/n): "); c = getchar(); printf("\n"); while( c != 'D' && c != 'd' && c != 'N' && c != 'n') { temp = getchar(); //eat the \n from the input above printf("Sorry, please type in D or N for"); printf("DEAL or NO DEAL: "); c = getchar(); printf("\n"); } if ( c == 'D' || c == 'd') { printf("\nCongratulation!! You have earn %3.0d on today!!", chh); printf("\nThank you for coming...\n"); return(0); } /* Second chose */ temp = getchar(); printf("\nWell, you have choose NO DEAL again let's eliminate a suitcase from here"); printf("\nNOTE: You can't change once you chose, so think hard!!"); printf("\nEliminate: %d %d", p0 - 48, p1 - 48); printf("\nYou choose: "); p2 = getchar(); temp = getchar(); /* replace the value with the suitcase number */ { if ( p2 == '1') { ch2 = s[0];} else if (p2 == '2') { ch2 = s[1];} else if (p2 == '3') { ch2 = s[2];} else if (p2 == '4') { ch2 = s[3];} else if (p2 == '5') { ch2 = s[4];} else if (p2 == '6') { ch2 = s[5];} else if (p2 == '7') { ch2 = s[6];} else if (p2 == '8') { ch2 = s[7];} else if (p2 == '9') { ch2 = s[8];} else { ch2 = s[9];} } ch2 = ch1 - ch2; chh = ch2%6498; chh = chh/7; printf("\n"); printf("\nOur suitcases average value is %3.0d right now", chh); printf("\nDo you want the AVERAGE instead of your suitcase's value?"); printf("\nDEAL or NO DEAL (d/n): "); c = getchar(); printf("\n"); while( c != 'D' && c != 'd' && c != 'N' && c != 'n') { temp = getchar(); //eat the \n from the input above printf("Sorry, please type in D or N for"); printf("DEAL or NO DEAL: "); c = getchar(); printf("\n"); } if ( c == 'D' || c == 'd') { printf("\nCongratulation!! You have earn %3.0d on today!!", chh); printf("\nThank you for coming...\n"); return(0); } /* LAST chose */ temp = getchar(); printf("\nWell, NOW is your last choose let's eliminate a suitcase from here"); printf("\nNOTE: You can't change once you chose, so think hard!!"); printf("\nEliminate: %d %d %d", p0 - 48, p1 - 48, p2 - 48); printf("\nYou choose: "); p3 = getchar(); temp = getchar(); /* replace the value with the suitcase number */ { if ( p3 == '1') { ch3 = s[0];} else if (p3 == '2') { ch3 = s[1];} else if (p3 == '3') { ch3 = s[2];} else if (p3 == '4') { ch3 = s[3];} else if (p3 == '5') { ch3 = s[4];} else if (p3 == '6') { ch3 = s[5];} else if (p3 == '7') { ch3 = s[6];} else if (p3 == '8') { ch3 = s[7];} else if (p3 == '9') { ch3 = s[8];} else { ch3 = s[9];} } ch3 = ch2 - ch3; chh = ch3%6498; chh = chh/6; printf("\n"); printf("\nOur suitcases average value is %3.0d right now", chh); printf("\nDo you want the AVERAGE instead of your suitcase's value?"); printf("\nDEAL or NO DEAL (d/n); "); c = getchar(); printf("\n"); while( c != 'D' && c != 'd' && c != 'N' && c != 'n') { temp = getchar(); //eat the \n from the input above printf("Sorry, please type in D or N for"); printf("DEAL or NO DEAL: "); c = getchar(); printf("\n"); } if ( c == 'D' || c == 'd') { printf("\nCongratulation!! You have earn %3.0d on today!!", chh); printf("\nThank you for coming...\n"); return(0); } else { printf("\nThat means you just don't want the average at there~"); printf("Let's open your suitcase~ "); printf("\nWant to find out~!? Pass ENTER!"); temp = getchar(); printf("\nYou have earn %3.0d on today!!", (ch0%6498)/8); printf("\nThank you for coming...\n"); return(0); } return(0);}int rand(void){ next = next * 10 + 125; return (unsigned int)(next/63)%500;}void srand(seed){ next = (seed%500);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -