newbiez! Helppppp

This is a discussion on newbiez! Helppppp within the C++ Programming forums, part of the General Programming Boards category; can someone show me how to do this Q ? read a number and print it out digit by digit ...

  1. #1
    Irene
    Guest

    Unhappy newbiez! Helppppp

    can someone show me how to do this Q ?

    read a number and print it out digit by digit as a series of words.Example:the numbers 123 would be printed as"five two three".


    thanks a lot,guys..waiting......

  2. #2
    Registered User cody's Avatar
    Join Date
    Sep 2001
    Posts
    86
    Well...

    what have you done so far, hm?
    Ah no...let me guess...nothing?!

    Think about it and begin with some lines, then post your code, I'm sure there'll be some people willing to help...

    aloa
    cody
    #include "reallife.h"

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    32
    I would use an if statement
    if(x==1)
    cout<<"one";
    I am a C++ newb
    using: Visual C++ 6.0
    thanx for any Help

  4. #4
    Unregistered
    Guest
    Since this is homework, I am not going to give you any actual code because then you will not learn. However, I will give you the idea.

    Start by having them input an array of characters. Then, use a for loop to go through character by character and display the appropriate word using a switch. Good luck,

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    Is this what you want??

    #include <iostream.h> //text input and output

    void main(void)
    {
    char number[15]; //declare our number
    int loop = 0; //what we use to keep track of the number we are up to
    cout << "Please Enter Your Number... \n";
    cin.getline(number, 20); //get the word into number
    cout << "Your Number in Words: \n";
    while (number[loop] != '\0') //while not the endd of the loop
    {
    switch(number[loop++]) //like saying: if (number[loop] == '?')
    {
    case '1': cout << "One "; break;
    case '2': cout << "Two "; break;
    case '3': cout << "Three "; break;
    case '4': cout << "Four "; break;
    case '5': cout << "Five "; break;
    case '6': cout << "Six "; break;
    case '7': cout << "Seven "; break;
    case '8': cout << "Eight "; break;
    case '9': cout << "Nine "; break;
    case '0': cout << "Zero "; break;
    } //end of switch
    } //end of loop
    cout << "\nPlease Press A Key Then Enter To Exit..."; //sometimes the window will dissapear so put this here.
    cin >> loop;
    }


    That should work. If your using c just change the #induce file and the cin and cout to the c ones.
    ...

  6. #6
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    well

    how exactly does cin.getline work? I know you can put 3 things in the parentheses, the first is the variable to put it in. but then what are the other two things for?

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    14
    takes the line with spaces and so forth

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    cin.getline

    the first one is the string (array of characters) to put data into. The second one is how many characters from the line to read (mayby you only want a 5 letter word) and I dont know what the last one does but you don't have to put it there. Hope that helps
    ...

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    32
    the last space is exit condition
    I am a C++ newb
    using: Visual C++ 6.0
    thanx for any Help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help!I am a NewBiez
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 12-10-2001, 09:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21