-
-
Save jaredonline/1231156 to your computer and use it in GitHub Desktop.
/* Here's what you've got */ | |
/* | |
Problem 2: You are asked to implement an automated number-to-language translation system for a phone com- pany. Write a C program that receives as an input an integer number and converts each digit of the number to an English word. The integer number can be of any length. | |
Sample program execution: | |
Please enter your phone number: 2345769854 two three four five seven six nine eight five four | |
*/ | |
#include<stdio.h> | |
int main(void) | |
{ | |
int numbs; | |
char ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN; | |
printf("Give a number to be converted: "); | |
scanf("%3d", &numbs); | |
switch (numbs) { | |
case 0: | |
printf("ZERO\n"); | |
break; | |
case 1: | |
printf("ONE\n"); | |
break; | |
} | |
return (0); | |
} | |
/* consider your what you're doing... in plain english: | |
Your program: "Hey user, give me a number" | |
Your user: "Okay, here's '12345'" | |
Your switch statement then says, "Does the number equal 1? Nope. Does it equal 2? Nope" etc. | |
You need to take the input and split it up into single digits first, then do the comparison. | |
*/ |
Aha! Take out a piece of paper. Pretend I gave you the number "12345", and fill out the following table for each iteration through the loop
rem | numbs
----------------
5 12345
That's the setup before you enter the loop, you do the rest and see if you can pinpoint the mistake.
Just a heads up (so you don't think I just decided to bail after the homework deadline, because I am definitely not doing that!), I had a physics exam yesterday and a Diff Eq exam today, so either later tonight or tomorrow I'll get back to work on this! :)
Cool [= Glad to hear it. Let me know if you make any progress or get stuck anywhere or have any questions.
Oops! Totally forgot to check back on this with you; I ended up asking a bunch of questions during our 3 hour lab in this class (like three days after doing all this with you) and figured everything out completely. Thanks again though man! :D
No worries. What was the solution?
Damn! I didn't end up getting it to work before i turned it in, but whatever. I am still getting an infinite loop though; this is what i have:
include<stdio.h>
int main(void)
{
int numbs,rem;
char ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN;
printf("Give a number to be converted: ");
scanf("%d", &numbs);
rem=numbs%10;
do
{
switch (rem) {
case 0:
printf("ZERO\n");
break;
ect....
;
}
numbs=numbs/10;
} while (rem > 0.1);
return (0);
}
any idea on what's going on?