im a 1st year comsci student and we are given an assignment that will display in words the number that is entered using logical operators and what we've learned so far(printf, scanf,etc.)
I only have problems in displaying the numbers from 11-19 (when I input 12 is displays two twelve), and when i got through it comes another problem with the ones digits (when I input 1 nothing comes out).
pls help..
here's the code so far..
#include<stdio.h>
#include<conio.h>
main()
{
int num, a,w,x,y,z;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);
a=num/1000;
if (a==1)
printf("one thousand");
else if (a==2)
printf("two thousand");
else if (a==3)
printf("three thousand");
else if (a==4)
printf("four thousand");
else if (a==5)
printf("five thousand");
else if (a==6)
printf("six thousand");
else if (a==7)
printf("seven thousand");
else if (a==8)
printf("eight thousand");
else if (a==9)
printf("nine thousand");
y=num%1000;
if (y>=100&&y<200)
printf(" one hundred");
else if (y>=200&&y<300)
printf(" two hundred");
else if (y>=300&&y<400)
printf(" three hundred");
else if (y>=400&&y<500)
printf(" four hundred");
else if (y>=500&&y<600)
printf(" five hundred");
else if (y>=600&&y<700)
printf(" six hundred");
else if (y>=700&&y<800)
printf(" seven hundred");
else if (y>=800&&y<900)
printf(" eight hundred");
else if (y>=900&&y<1000)
printf(" nine hundred");
z=num%100;
if (z>=20&&z<30)
printf( " twenty");
else if (z>=30&&z<40)
printf( " thirty");
else if (z>=40&&z<50)
printf( " forty");
else if (z>=50&&z<60)
printf( " fifty");
else if (z>=60&&z<70)
printf( " sixty");
else if (z>=70&&z<80)
printf( " seventy");
else if (z>=80&&z<90)
printf( " eighty");
else if (z>=90&&z<100)
printf( " ninety");
if (x<10&&x>20)
x=z%10;
if (x==1)
printf(" one");
else if (x==2)
printf(" two");
else if (x==3)
printf(" three");
else if (x==4)
printf(" four");
else if (x==5)
printf(" five");
else if (x==6)
printf(" six");
else if (x==7)
printf(" seven");
else if (x==8)
printf(" eight");
else if (x==9)
printf(" nine");
if (x>10&&x<20)
{ printf("");}
w=num;
if (w==10)
printf("ten");
else if (w==11)
printf(" eleven");
else if (w==12)
printf(" twelve");
else if (w==13)
printf(" thirteen");
else if (w==14)
printf(" fourteen");
else if (w==15)
printf(" fifteen");
else if (w==16)
printf(" sixteen");
else if (w==17)
printf(" seventeen");
else if (w==18)
printf(" eighteen");
else if (w==19)
printf(" nineteen");
getch();
}