# Thread: Switch Statement (For Beginner)

1. ## Switch Statement (For Beginner)

Sorry, beginning programmer. Assignment: Take an integer keyed in from the terminal and extract and display each digit of the integer in English. Ex. 932 --> nine three two

Code:
``` /*This program takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English.*/

#include<stdio.h>
int main(void)
{
//DECLARE VARIABLES
int num;

//ASK USER FOR INPUT; STORE
printf("Please enter an integer: ");
scanf("%d", &num);

//SWITCH STATMENT
switch (num)
{

case 0:
printf("zero\n");
break;
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;
default:
printf("none");
break;
}

return 0;
}```
I don't know how the program works if the integer is more than one digit. Any hints would be greatly appreciated!

2. The way it works now is that, if a value of 10 or more (i.e. more than one digit) is entered, the code will print out "none".

You need to implement a loop that repeatedly divides by 10 and extracts modulo 10 to extract the individual digits. The catch is the "natural" way of doing that will print the digits in reverse order. That means you need to store each digit in (say) an array, so you can then output the results in the desired order.

And, since this is a homework problem, that's all the advice you'll get. This site has a homework policy that amounts to "You have do do your own homework, not expect it to be done".

Popular pages Recent additions