this is the first part of a program i have to make for a class and i need help with the guessing game part.
when i type in a number to guess what number the computer has, it always says that i've guessed the right number
here is the code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int x, y;
int z = 0;
printf("Welcome!\n");
printf("Please select a game to play by typing in the correct number.\n");
printf("1. Play the number guessing game between 1 and 50\n");
printf("2. Play Rock, Paper, Scissors\n");
printf("3. Display the Area of a rectangle\n");
printf("4. Quit\n");
scanf("%d\n", &x);
if (x = 1){
int stime;
long ltime;
int randomnumber = rand() % 51;
ltime = time(NULL);
stime = (unsigned) ltime/2;
srand(stime);
printf("Please enter a number between 1 and 50.\n");
scanf("%d\n", &y);
while (z < 1){
if (y = randomnumber){
printf("Congratulations! you guessed the correct number. Now exiting.\n");
z++;
}
else if (y < randomnumber){
printf("Guess higher\n");
scanf("%d\n" , &y);
}
else if (y > randomnumber){
printf("Guess lower\n");
scanf("%d\n" , &y);
}
}
exit(0);
this is not the full program so somethings don't need to be brought up to me.
the program has no errors, but the wording is wrong somewhere.