Hey everyone!
I need a little help with my code... I have made a simple game where you have to guess the number, which has been created by the RNG, and it helps you to get closer to the number by saying : Choose a bigger number / choose a smaller number... and when you finally enter the right number it says : Congrats , you won. But then i would like to know in the end of the programm, that how many times you had to guess to get the correct number. Here's what i have been trying to do, here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int x = rand()%10;
int i,n=0,tip=0;
int array[tip];
do {
printf(" Enter a number.\n");
scanf("%d",&array[tip]);
if (array[tip]<x) {
printf("Enter a bigger number.\n");
} else if (array[tip]>x) {
printf("Enter a smaller number.\n");
} else {printf("Congratz, you won!\n");
}
}while(array[tip]!=x);
for(i=0;i<10;i++)
if(tomb[tipp]=x) {
n= sizeof(tomb)/sizeof(tomb[i]);
}
printf("You had to guess %d times to win!\n", n);
return 0;
}
Please help me if you can!