-
noob help if /else
iam creating a program that the user will enter (upper/lower case) from A-H or (a-h)
how can i do that with an if statement this is what i did. but is not working
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main ()
{
system("cls");
float a;
scanf("\n%f",&a);
if((a==A)||(a==H)&&(a==a)||(a==h));
{
printf("hi");
}
else
{
printf("hello");
}
getch();
}
-
Firstly, declare it as
not float a
You are just inviting trouble there.
Code:
if (((c >= 'A') && (c <= 'H')) || ((c >= 'a') && (c <= 'h'))) {
What that does is get an ASCII comparison
-
Also...
You are scanning it in wrong.
If it's a character, it should be %c not %f.
Also, use getchar() instead of scanf