1. ## boolean operator ||

I know similar Q's have ben posted with this problem, and found the answers insightful.
But when I enter, for eg. 4, I get a response of "Invalid Input"
Code:
``` if (cInput < 1 || cInput > 10) { //if2
printf("Invalid Input!\n");
}//if 2```
I take this as
if 4 is less than 1 (false)
or
if 4 is greater than 10(false)

both are false, so I thought it should move on to the else statement, but I think the program reads (true) therefore "Invalid Input"

The reason might be becasue I have too many if/else statements, but i dont know how else to do it???
Anyway, whats wrong with my boolean?

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>

int main(){
char cInput = '\0';	//place to store input
int iRandomNum = 0;	//place to stroe random num

srand(time(NULL)); // makes sure num is really random, don't forget
//Null. time() has to take a paramter inside the ()
// use NULL otherwise it holding garbage

iRandomNum = (rand() %10) + 1; // find a rand num btween 1 -10
// add 1 becase starts at 0, so really 0-9

printf("Please enter a number between 1 - 10: ");
scanf("%c", &cInput);

if (isdigit(cInput)) { //if1  test if cInput is true
if (cInput < 1 || cInput > 10) { //if2
printf("Invalid Input!\n");
}//if 2
else { //else2
if (cInput == iRandomNum) { // if3
printf("\nSuccess, you guessed right!\n");
}	//if3
else { //else3
printf("\nSorry, the correct answer was %d.\n", iRandomNum);
} //else3

} //else2

}//if1
else {	//else 1
printf("You did not enter a digit!\n");
}	//else 1

return 0;
}	//main```
thanks

2. cInput is a character not an integer. When you are doing the comparison it's comparing the ASCII code of cInput rather than it's integer value.

3. ofcoarse, thank you

4. So I need to store the value in an int aswell.
I have to keep the idigit check because its part of the assignment.
So I need to store the int as %d somehow.
Is there a way to store the input in both %d char and %i int using scanf, without entering it twice and without using pointers.
Or changing the Ascii char back to a value and putting it in an in iInput to use in my if/else statements?

6. Take note that atoi is retarded about 0. So if your input can be 0, maybe strtol() is a better choice.

7. You can also just use int and %d, are there any reason why you want a character? Your dealing only with numbers here after all. Scanf has a return value that you can check if you want to make sure that the input was read correctly.

8. int iInput;
//after scanf("%c", &cInput);
iInput = atoi (cInput);
I get a warning "passing argument 1 of 'atoi' makes pointer from integer without cast"

I tried to typecast
iInput = atoi ((int)cInput); but this is probably wrong too.

when run the program I get a bad access report in command window

9. atoi expects a string. However you can also do like this:

Code:
```        ret = scanf("%d", &cInput);
if(!ret){
puts("Expected a number");
return 1;
}```

10. @ Subsonics the problem i am working on is
"Build a number guessing game that uses input validation (isdigit() function) to verify that the user has entered a digit and not a non-digit (letter). Store a random number between 1 and 10 into a variable each time the program is run. Prompt the user to guess a number between 1 and 10 and alert the user if he was correct or not."

though after reading the question again, I think the solution is to use 2 different inputs,
1. input a num, then check it is a digit
2. input a number for a random num guessing game.

anyway at least I learnt a little about atoi() for when I come across it in the future.

Thanks

11. Subtract '0' from your character to obtain its equivalent integer.

12. Subtracting 0 will give the the corresponding Ascii number won't it? i.e. 'A' char , 'A' - 0 = 65.
I want the original number (entered into the char - isdigit test) turned from char back to int.

13. Look closely. It says subtract '0', ie the ASCII equivalent for the number 0.
Since '0' is the ASCII equivalent with 0, it then seems feasible that subtracting '0' would yield 0. And since '1' is '0' + 1... well, you get the point.

14. Oh yes, very interesting, Thank you Elysia.