a small c problem

Discussion in 'QnA (read only)' started by aniishvara@gmail.com, Jul 25, 2006.

Thread Status:
Not open for further replies.
  1. aniishvara@gmail.com

    aniishvara@gmail.com New Member

    Joined:
    May 20, 2006
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    i have 2 questions in my book for which i am not able to decide on the exact solution..

    ? 1- write a program to accept any number upto 6 digits and print that in a string.
    Eg:
    input number 1034
    output string one thousand thirty four
    ? 2- write a program to accept any date in numbers annd print that in string
    Eg
    input date: 19/3/96
    output string nineteen march ninety six.
     
  2. Sykora

    Sykora I see right through you.

    Joined:
    Sep 10, 2005
    Messages:
    597
    Likes Received:
    4
    Trophy Points:
    0
    Location:
    Chennai
    Since it's probably a homework question, I'm not going to give the answer as code.

    In both, you need to extract the digits one by one, and display accordingly.

    Use a loop to extract the digits, and store them in variables. Then output them after the loop has finished.
     
  3. nik_for_you

    nik_for_you New Member

    Joined:
    Apr 21, 2004
    Messages:
    313
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Paris
    use of arrays,pointers will help you .. had done both programs in past.. try it own dear
     
  4. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    I am glad you guys didn't give out the code :D This surely is a homework problem! Solve it on your own man! These guys have given you enough hints!

    I have done this in COBOL when I learnt it :)) You can't do it in C? ;) Try it. Its easy. You can do it.
     
  5. OP
    OP
    aniishvara@gmail.com

    aniishvara@gmail.com New Member

    Joined:
    May 20, 2006
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    hey guys @ least tell me how to go abt that 18 ,19 etc nos...
    ie how do i print the appropriate string saying eighteen ,or one or two,,,
    for all the dates in a month!!!
     
  6. dheeraj_kumar

    dheeraj_kumar Legen-wait for it-dary!

    Joined:
    Dec 19, 2004
    Messages:
    2,470
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Chennai
    get each number and its place(ones place, tens place, hundreds place etc) and write a function to convert a number to text (basic like 9-nine) and add suffixes based on the place. remember there are lots of exceptions in this pogram because 18 is eight-een and 17 is seven-teen but 11 is not one-een. get what I'm saying? this confusion is only in 2 digit numbers till 20, so from that its easy
     
  7. aditya.shevade

    aditya.shevade Console Junkie

    Joined:
    Jun 29, 2006
    Messages:
    990
    Likes Received:
    3
    Trophy Points:
    0
    Location:
    USA
    Are you suggesting using the % (reminder tag?)

    Aditya
     
  8. OP
    OP
    aniishvara@gmail.com

    aniishvara@gmail.com New Member

    Joined:
    May 20, 2006
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    no ...u r not right!!! cos i have to print it as eleven for 11 , and not split the numbers as one one or for that matter 18 as eight-een
    any numbershould be printed as we read it

    like eighteen, 25 as twenty five itself and not like two-five as stated by u!!!

    c this is the problem..and i do not want to use some stupid switch case or some else if ladders to print it appropriately!!!
     
  9. paul_007

    paul_007 New Member

    Joined:
    Jan 21, 2005
    Messages:
    801
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    earth
    hi tuxfan, so u know to code programs in cobol , cud u pls suggest me some ebooks, or tutorials on cobol cause i'm also learnin COBOL, for AS 400 and mainframes.
     
  10. sakumar79

    sakumar79 Active Member

    Joined:
    Nov 28, 2004
    Messages:
    2,441
    Likes Received:
    9
    Trophy Points:
    38
    Location:
    Madurai
    Extract the last two digits: for one to twenty they have to have separate switches, for above twenty, you put one switch for each of the two digits. Then, go to the next digit for hundred, and so on...

    Arun
     
  11. tuxfan

    tuxfan New Member

    Joined:
    Feb 4, 2004
    Messages:
    2,653
    Likes Received:
    9
    Trophy Points:
    0
    Location:
    Mumbai
    :( That was many years ago! I don't remember anything in COBOL now. Completely out of touch :(
     
  12. ilugd

    ilugd Beware of the innocent

    Joined:
    Dec 25, 2005
    Messages:
    1,009
    Likes Received:
    3
    Trophy Points:
    0
  13. puja399

    puja399 New Member

    Joined:
    Jul 30, 2005
    Messages:
    324
    Likes Received:
    0
    Trophy Points:
    0
    Create a dictionary in an array, and u don't have to use 'case' or 'else if ' ladders.
     
  14. OP
    OP
    aniishvara@gmail.com

    aniishvara@gmail.com New Member

    Joined:
    May 20, 2006
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    wat is a dictionary in an array???
    and how wud u create a dicitonary in an array???
     
  15. Sykora

    Sykora I see right through you.

    Joined:
    Sep 10, 2005
    Messages:
    597
    Likes Received:
    4
    Trophy Points:
    0
    Location:
    Chennai
    Methinks puja399 is confused, dictionaries are native python...or so I believe.
     
  16. ilugd

    ilugd Beware of the innocent

    Joined:
    Dec 25, 2005
    Messages:
    1,009
    Likes Received:
    3
    Trophy Points:
    0
    c or c++?? @puja??
     
  17. sakumar79

    sakumar79 Active Member

    Joined:
    Nov 28, 2004
    Messages:
    2,441
    Likes Received:
    9
    Trophy Points:
    38
    Location:
    Madurai
  18. Garbage

    Garbage God of Mistakes...

    Joined:
    Dec 26, 2005
    Messages:
    1,909
    Likes Received:
    8
    Trophy Points:
    0
    Location:
    Pune, Maharashtra
    I think he should first check the number of Digits in given input.

    ex. 10,286. Here it is 5. Hence the output string must contain "Thousand".

    Then it is easy to write the code. Bcoz TEN is same for Lacks, Hundreds & TEN also.

    Isn't it?
     
  19. puja399

    puja399 New Member

    Joined:
    Jul 30, 2005
    Messages:
    324
    Likes Received:
    0
    Trophy Points:
    0
    Exactly so, however, u can implement a simple map in C using a 2D array.
     
  20. Official Techie

    Official Techie New Member

    Joined:
    Jan 25, 2005
    Messages:
    439
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Somewhere in motherboard
    Why don't you start a new thread for your problem? Don't hijack threads
    -tuxfan



    i have a problem in c++


    #include<iostream.h>
    class outer { int a;
    class inner {
    int b;
    public:
    int c:
    void prn(void)
    {
    cout<<endl<<"inner :: prn()"<<endl;
    cout<<b<<c<<endl;
    }
    inner()
    {
    b = 5;
    c = 10;
    }

    };
    inner ob1;
    public:
    inner ob2;
    void second(void)
    {
    cout<<endl<<"Outer::second()"<<endl;
    cout<<ob2.c<<endl;
    cout<<"A = "<<a<<endl;
    ob1.prn();
    }
    outer()
    {
    a = 25;
    }
    };

    void main()
    {
    outer ab;
    ab.second();
    ab.ob2.prn();
    }





    the errors are

    --------------------Configuration: example of nested class - Win32 Debug--------------------
    Compiling...
    example of nested class.cpp
    D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(7) : error C2062: type 'void' unexpected
    D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp( 8 ) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
    D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(39) : error C2039: 'prn' : is not a member of 'inner'
    D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(3) : see declaration of 'inner'
    Error executing cl.exe.

    example of nested class.obj - 3 error(s), 0 warning(s)
     
    Last edited by a moderator: Jul 30, 2006
Thread Status:
Not open for further replies.

Share This Page