コード例 #1
0
int main()
{	
	int number, guess, difference, option;/*defines integers*/
	char play_exit;/*defines players choose*/
	/*print to screen questions for play or exit?*/
	printf(" “P” or “p” for play and “E” or “e” to exit\n");
	option=Play(play_exit);/*players choice*/
	/*this loop for play game if players choice is 'p',*/
	while(option==1) {
		number=RNG();/*create the random number*/
		/*this loop for continue if players choice is wrong.*/
		while(number!=guess) {
			printf("Please guess between 1 and 10 ");/*wants guess*/
			scanf("%d", &guess);/*take the guess*/
			/*calculate the difference*/
			difference=CalculateTheDifference(guess,number);
			/*print to screen the feedback*/
			WarnThePlayer(difference,number);
		}
		/*print to screen questions for playing again?*/
		printf(" Do you want to play again?(“P” or “p” for play and “E” or 			“e” to exit)\n");
		scanf("%c", &play_exit);/*take the players choice*/
		option=Play(play_exit);/*define the choice*/
	}
	return 0;
}
コード例 #2
0
int main()
{	
	int  a1, a2, guess1, guess2, x1, x2;/*defines number,guess,difference */
	/*For 1st number.*/
	a1=RNG();/*calculate 1st number*/
	printf("Guess please?\n");/*wants guess*/
	scanf("%d", &guess1);/*read guess*/
	printf("Your guess= %d\n", guess1);
	x1=CalculateTheDifference(guess1, a1);/*calculates the difference*/
	WarnThePlayer(x1, guess1);/*writes the results*/
	/*For 2nd number*/
	a2=RNG();/*calculate 2nd number*/
	printf("Guess(between 1-10) please?\n");/*wants guess*/
	scanf("%d", &guess2);/*read guess*/
	printf("Your guess= %d\n", guess2);
	x2=CalculateTheDifference(guess2, a2);/*calculate the difference*/
	WarnThePlayer(x2,guess2);/*writes the results*/


}
int 
main(void){

    int number; 
    int guess;
    int result;
    
    /*Prints the screen instructions and comments*/
    printf("\nWELCOME");
    printf("\nI've got a number for you");
    printf("\nIs a number between 1 and 10");
    printf("\nCan you guess this number?");
    printf("\nI'm giving you two chances, good luck!");
    printf("\n\nEnter your guess:");
    
    /*Player's guess*/
    scanf("%d",&guess);
    
    /*The correct answer assign to number*/
    number = RNG();
    
    /*Calculates the difference between guess and correct number*/
    result = CalculateTheDifference(number, guess);
    
    /*Print screen the comment according to the result*/
    WarnThePlayer(result);
    
    /*If the guess is correct the program ends*/
    /*If the guess isn't correct player enter the second time guess*/
    if(result==0)
    return 0;
    else{
    printf("\n\nThis is your last chance:");
    scanf("%d",&guess);
    
    number = number;
    result = CalculateTheDifference(number, guess);
    
    if(guess==number)
    printf("---------------------CONGRATULATIONS!!!---------------------\n\n");
    else
    printf("\nI'm sorry, the correct number is:%d\n\n", number);
    }
    
    return 0;
}