Hello!
I am starting with c programming and I have an error i cannot fix!
who can help me?
We can try...
#include <stdio.h>
#include <ctype.h>
In which of those lines do you get the error 1036?
Beside that,
srand is defined in
stdlib.h, which you do not include and
time() is defined in
time.h (also missing the include) but in a different format...
int main() {
int iResponse = 0;
int RandomNum = 0;
srand(time());
See comments above...
iRandomNum = (rand()%10)+1;
Typo at least, you define above a variable of type
int named
RandomNum but then you are trying to use a var named
iRandomNum here...
if (iResponse == RandomNum){
Here, you are opening up a code block with a curly bracket, but you don't close that code block...
printf("\nLucky guess!!!!\n");
}
Here you need to add a closing curly bracket
else /* (iResponse != RandomNum) */
There's no condition without a preceding "if" and in this case, you can ommit it in the first place (if the "==" condition does not apply, "!=" is automatic, there is no "maybe" condition)
printf("\nWRONG!!!!!"\n);
The trailing "\n" belongs inside the string...
printf("\nThe number was %d\n");}
You are actually missing to include the value for the %d in the format string, which should be RandomNum
}
Now I get an error 1036: Syntax error in #include. before i got much more errors but i could deal with them.
You get a lot more than that...
At the very least, you program should look like this...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
int main() {
int iResponse = 0;
int RandomNum = 0;
srand(time());
RandomNum = (rand()%10)+1;
printf("quess a number between 1 and 10: ");
scanf("%d", &iResponse);
if (isdigit(iResponse) != 0){
printf("/nThis is not a number moron/n");
}
if (iResponse == RandomNum){
printf("\nLucky guess!!!!\n");
}
else // (iResponse != RandomNum)
printf("\nWRONG!!!!!\n");
printf("\nThe number was %d\n", RandomNum);
} // end of main
This still complains about the
time() call, I leave that as the last obstacle for you,as we do not do homework for other here in the forum...
You also can do yourself a huge favor if you get used to a proper indentation style, it really helps to write readable programs. And as far a s proper sequences of opening/closing brackets goes, the editor of the IDE gives you a lot of hints, so there is no real excuse to make mistakes here...
Ralf