Hello, first post here, I'm writing a simple program and need some help.
I get a fatal error whenever I run this program, and I cannot assess why.
Should the for loop not stop once it reaches a scanf function? As I am assuming the program is crashing because it loops into infinity I think that's the problem. I would greatly appreciate it if someone could enlighten me as to whats going on.
Also, I'm aware that it makes far more sense to use a while loop but I'm asking this question to help me in understanding the for function, not particularly how to re-write the program using other methods.
/****************************/
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int myguess;
int compguess=rand() %100;
int final=1;
printf("Welcome, to the number guessing game, I have chosen a number, now you must choose yours.");
scanf("%d",myguess);
for(;final==0;)
{
if(myguess>compguess);
{
printf("You guessed %d, which is higher than the number I have chosen.",myguess);
printf("\nGuess again: ");
scanf("%d",myguess);
}
if(myguess<compguess);
{
printf("You guessed %d, which is less than the number I have chosen.",myguess);
printf("\nGuess again: ");
scanf("%d",myguess);
}
if(myguess==compguess);
{
printf("You guessed %d, which is the number I have chosen. Good job & goodbye.",myguess);
final=1;
}
}
return(0);
}