You need to use int
type in conjuction with %d
specifier, and char
with %c
specifier. And %u
with unsigned integers.
#include<stdio.h>
int main()
{
unsigned int one=0; unsigned int two=0;
printf("Quantity 1 = ");scanf("%u",&one);
printf("Quantity 2 = ");scanf("%u",&two);
printf("The value is %u",one);
return 0;
}
Basicaly, scanf
will try to read integer from input and it will try to store it inside memory location that is not large enough, so you will have undefined behavior.
You can find good reference here.
However, if you try to use character for an input type, you may want ask yourself why you won't get a chance to enter a second Quantity (if you type 4
and press enter). This is because second scanf
will read enter key as a character. Also, if you try to type 21
(for a twentyone), it will fill the first value with 2
and second with 1
(well, with their ASCII values).
So, be careful - be sure that you always choose the right type for your variables.