Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Hey i need help with writing a simple program

blindleafblindleaf Member Posts: 6
Ok i have an assigment in my computer science 104 class in college it goes as follows:

Write a program that reads in a number supplied by the user and prints out that number in words. For example, if I were to type in:
125
The program should respond with:
one hundred twenty-five
Be careful to test this program so that it works with all numbers in the range 0 to 9999.

I need this to work with while loops and if statements only if possible, anything will help just a way i could start off trying to learn this. Thanks anyone,

Ryan Perrott

Comments

  • BriballBriball Member Posts: 265
    Okay, I'm going to brainstorm out loud here so...

    First, I'd convert the number to a string so:

    //num will be our number:

    char string[64], one[64], final[64];

    sprintf(string, "%i", num);

    Then, I'd test each individual "digit" now a character:

    while(i < strlen(string))
    {
    if(string[i] == '0')
    //it can be 0 - 9...
    strcpy(one, "Zero");
    strcat(final, one);

    }

    So, keep testing the digits until you are done. For each digit, make one equal to that number in words, then add it to the final string. Then, print out the final:

    cout >> final;

    or
    printf();

    Hope this gets you somewhere on track.

  • ricosuavericosuave Member Posts: 33
    remember to do pseudocode and a flowchart before you start programming
    the clearer the idea ,the clearer the sequence of logical events,the easiest way to program.
    : Ok i have an assigment in my computer science 104 class in college it goes as follows:
    :
    : Write a program that reads in a number supplied by the user and prints out that number in words. For example, if I were to type in:
    : 125
    : The program should respond with:
    : one hundred twenty-five
    : Be careful to test this program so that it works with all numbers in the range 0 to 9999.
    :
    : I need this to work with while loops and if statements only if possible, anything will help just a way i could start off trying to learn this. Thanks anyone,
    :
    : Ryan Perrott
    :

  • Justin BibJustin Bib USAMember Posts: 0

    ____ ( http://forcoder.org ) free video tutorials and ebooks about | Visual Basic .NET PL/SQL Ruby Python Swift Go R C Scratch C++ MATLAB Perl Objective-C Assembly Visual Basic Delphi JavaScript Java C# PHP Apex Awk Alice Ada Hack Scala Lua FoxPro Bash D Erlang Rust VBScript COBOL F# Clojure Scheme Transact-SQL SAS Logo Dart Crystal Kotlin ABAP ML Prolog Lisp Fortran LabVIEW Julia | __

Sign In or Register to comment.