Skip to content

Instantly share code, notes, and snippets.

@jaredonline
Created September 21, 2011 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredonline/1231156 to your computer and use it in GitHub Desktop.
Save jaredonline/1231156 to your computer and use it in GitHub Desktop.
Homeworks
/* 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.
*/
@jaredonline
Copy link
Author

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.

@afelli
Copy link

afelli commented Sep 22, 2011

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! :)

@jaredonline
Copy link
Author

Cool [= Glad to hear it. Let me know if you make any progress or get stuck anywhere or have any questions.

@afelli
Copy link

afelli commented Oct 3, 2011

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

@jaredonline
Copy link
Author

No worries. What was the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment