Untitled

 avatar
unknown
scheme
3 years ago
1.3 kB
3
Indexable
#include<stdio.h>
#include<stdlib.h>
#include<time.h>


int level1(int); // declaring function for level 1 
int main(){
	int numOfLives1 = 3;
	srand(time(NULL));
	level1(numOfLives1);
	
	return 0;

}
//defining the function
int level1(int numOfLives1){
	int nComputerSecretNumber;	
	int nUserInput;
	int nMin = 1;
	int nMax = 10;
	printf("Enter the guess for computer's secret number: \n");
	scanf("%d", nUserInput);
	numOfLives1 = numOfLives1 - 1; // i did this because the user uses a guess when they guess, so the user loses 1 live.
	nComputerSecretNumber = rand()%nMax+nMin;


	while(nComputerSecretNumber != nUserInput && numOfLives1 != 0){
		if (nUserInput < nComputerSecretNumber){
			printf("The secret number is bigger than %d\n", nUserInput);
		} 
		else{
			printf("The secret number is smaller than %d", nUserInput);
		}
		printf("The number of the remaining guesses is: %d", numOfLives1);
		numOfLives1--;
		printf("The number is not correct. Try again. ");
		scanf("%d", nUserInput);
		
	}
	if ( numOfLives1 == 0 ){
		printf(" You've used all your guesses. The game is over.\n");		
		printf(" The correct number was %d", nComputerSecretNumber);
	}
	else{
		printf("Congratulations!!! %d was the correct number. \n", nComputerSecretNumber);
	}
	return numOfLives1;

}
Editor is loading...