How would I implement the rand or the srand statement into this C Programming language. I have been reading about these 2 statements but I am a bit confused still. In need of assistance. I am a beginner in Programming....
#include <stdio.h> //Main header
#include <stdlib.h> //Standard header tells the compiler to insert the
//contents of stdlib in a praticular place.
#include <time.h> //Time header
#define MAX_GUESSES 3
//Title of the game
int main(void) {
int i; //loop variable
int guess; //loop variable
int number = 13; //winning number for the game
int correct = 0; //0 = lose, 1 = win
printf("\nYou have 3 chances to guess a number from 1 to 20.\n");
//displays out on the computer screen
for(i =0; i < MAX_GUESSES; i = i + 1) { //Beginning of loop
printf("Enter a guess (1-20): "); //Displays the output on the screen
scanf("%d", &guess); //used to read information that's written
if(guess == number) {
printf("That's correct!\n");
correct = 1;
break; //Command that breaks the loop
}
else{
printf("Sorry, that's incorrect.\n"); //Shows the output if number guessed is wrong
}
} //end of loop
if(correct == 1) {
printf("You win!\n");
//Displays this message if the user guesses the correct number
}
else {
printf("Game over. You lose. The number was %d.\n", number);
//Displays this message if the user guessed wrong 3 times
}
return 0;
}