Hi, I'm writing a program, using switch statements only, and the problem is below:
Write a program, digitsToWords.c, that prompts the user to input a character in the range '0' to'9' (i.e. a digit character). If the user enters '0' the program should print out "ZERO"; if the input is '1' the ouput should be "ONE"; and so on. Any character outside the range '0' to '9' should cause the program to output "NOT A DIGIT". Use a switch statement
i've done most of the program, just need advice on the last part because I can't see what I've done wrong. Any time I enter a non digit, I just get 'zero' printed to the screen and not 'NOT A DIGIT', which I want. Here's what I've written so far:
Any help would be great thanks.Code:#include <stdio.h> int main() { int a; printf("Please enter a number between 0-9: "); scanf("%i", &a); switch (a) { case 1 : printf("one\n"); break; case 2 : printf("two\n"); break; case 3 : printf("three\n"); break; case 4 : printf("four\n"); break; case 5 : printf("five\n"); break; case 6 : printf("six\n"); break; case 7 : printf("seven\n"); break; case 8 : printf("eight\n"); break; case 9 : printf("nine\n"); break; case 0 : printf("zero\n"); break; default: printf("NOT A DIGIT!\n"); } return 0; }