Thread: Numbers in Text Format

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    1

    Question Numbers in Text Format

    I want to make a program in C that will convert any numbers in Text i.e. if any user enter 123 the program will show as "ONE HUNDRED TWENTY THREE". There will be another program that will show 123 as "ONE TWO THREE".

    Pls, make these programs, I need it urgent.

    Thanks.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Pls, make these programs, I need it urgent.
    You want to make a program or do pay somebody who will do it for you?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    is this for homework?

  4. #4
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Code:
    #include <stdio.h>
    
    const char* eng[] = {
    	"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
    	"EIGHT", "NINE"
    };
    
    void english(int n)
    {
    	int i, j, m;
    	char buff[16];
    	if (n < 0 && n)
    	{
    		printf("MINUS ");
    		n = -n;
    	}
    	i = 0;
    	do
    	{
    		m = n&#37;10;
    		buff[i] = m;
    		n /= 10;
    		i++;
    	} while (n);
    	while (--i >= 0)
    	{
    		printf("%s ", eng[buff[i]]); 
    	}
    	putchar('\n');
    }
    
    
    int main()
    {
    	int n;
    	printf("Number: ");
    	scanf("%d", &n);
    	english(n);
    	return 0;
    }

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Manav: It is part of this forums "Rules" to not post direct solutions to things that are likely to be "Homework assignments". Instead, we should help the original poster LEARN how to do it - learning by copying is not particularly useful, as it only teaches the use of CTRL-C/CTRL-V, which isn't what programming is about.

    See: http://cboard.cprogramming.com/annou...t.php?f=4&a=39

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Don't worry!
    If I were his teacher. I would ask him to explain it. And if he can explain it well.
    Well ... then I would not mind it at all if he has taken this solution from such message board.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Not all teachers will ask though, and those who do may still miss students who copy blindly.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    And the good thing about it is that it's not doing exactly what he asked for .
    if any user enter 123 the program will show as "ONE HUNDRED TWENTY THREE"
    Your solution will only show "ONE TWO THREE".

    But otherwise, nothing else to say on the code itself.
    Last edited by foxman; 01-23-2008 at 07:40 AM. Reason: Small correction

  9. #9
    Banned
    Join Date
    Nov 2007
    Posts
    678
    sorry. don't want to steal other person's thread. but.
    all teachers should be aware of a thing named Google.
    and they must also be aware of the thing named cboard.
    so if they just blindly accept the code submitted by their students.
    then at least they know what they are doing. and at least they don't care about the student.
    a student in the hands of such teacher is - hopeless already!

    i hope i could express it well.

    sorry for this off topic!

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Writing a program is harder than understanding it. So even if the OP can understand the code, that's not sufficient. Google isn't perfect, especially if the question was phrased so it's hard to detect with a search. Finally, the OP could delete their post so there's nothing to detect (although I copied this thread's just in case).

  11. #11
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    deb_cal2:

    Talk to the people on this site, not us
    Last edited by abh!shek; 01-23-2008 at 09:01 AM.

  12. #12
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    The main thing to understand i think is if you post a complete answer to a bone question you are not helping anybody really

  13. #13
    Banned
    Join Date
    Nov 2007
    Posts
    678
    i agree with all! [discussion closed]
    can someone please post the code that does the other thing asked by OP
    i mean...
    input: 123
    output: One Hundred Twenty Three
    i will pay nothing except my gratitude towards the kind enough coder

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    OP is supposed to write that him/herself.
    We will assist, not create the program.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Hey!
    It was so easy! Before, I was just wondering how to write
    Then I just started on it, and now I have written it (after 30 minutes).
    It can parse numbers from 0 to 999 only!
    I will not post the code here. Nor in PM
    The OP doesn't seem to be interested now.
    But thanks for the idea buddy. I made both the programs in under 30 mins.
    If you want you too should be able to make it without too much effort!

    And for help ... there are all the board members! ( Except me )


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading numbers from a text file
    By wolfindark in forum C++ Programming
    Replies: 12
    Last Post: 03-24-2007, 01:57 PM
  2. Comparing numbers to a list of numbers held in a text file
    By jmajeremy in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2006, 07:56 AM
  3. Backgammon
    By glo in forum Game Programming
    Replies: 5
    Last Post: 10-02-2006, 10:26 PM
  4. Seeking Format Advice
    By PsychoBrat in forum Game Programming
    Replies: 3
    Last Post: 10-05-2005, 05:41 AM
  5. Reading text in an Image format
    By loko in forum C Programming
    Replies: 0
    Last Post: 09-29-2005, 06:38 PM