I try to write a program that identify amounts of sale, and i also need to show an error message when a character is entered;
so i try the following:
but when i run the program, if i type
a
it will skip a line and wait for another input. so is there a way to correct this error??
And is it possible to do this just with int, because my teacher want us to do it with just int,(which is without using char).
so i try the following:
Code:
#include <stdio.h>
int main(int argc, char **argv){
int sale1, sale2;
char c1;
printf("Amount of Sale (inclusive of GST):");
scanf("%d.%d", &sale1, &sale2);
scanf("%c", &c1);
if (c1 >= 'A' && c1 <= 'Z'){
printf("Input error\n");
return 0;
}else if (c1 >= 'a' && c1 <= 'z'){
printf("Input error\n");
return 0;
}
.....
a
it will skip a line and wait for another input. so is there a way to correct this error??
And is it possible to do this just with int, because my teacher want us to do it with just int,(which is without using char).
Comment