CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Problem in C

  1. #1
    Join Date
    Sep 2002
    Location
    India (Delhi)
    Posts
    199

    Thumbs down Problem in C

    i need to create a program in 'C' which simulates LED displays (e.g., a digital clock or microwave). that can print the digits 0 through 9 as block digits (like you would find on an LED display). Each digit should contain only the x and . characters (see example output below), and should be followed by a blank line so the digits are separated. The input to this program will be a number followed by a height and a width. For example, with the input 25, 7, 5, the program will write the digits 2 and 5 (separated by a blank line) where each digit has a height of 7 and a width of 5 characters. Your program requires that the height be an odd number >= 5 and that the width be >= 3. Your program should check that the input line contains three numbers (value, height, and width) and that the height and width adhere to the constraints (height is odd and >= 5, width >= 3). It should inform the user of any input problems.
    Input Line: 256 5 5
    Output:
    Number - 256, Height - 5, Width - 5



    xxxxx
    ......x
    xxxxx
    x......
    xxxxx

    xxxxx
    x.....
    xxxxx
    ......x
    xxxxx

    xxxxx
    x......
    xxxxx
    x....x
    xxxxx



    I can draw the complete box with the given height and width but problem is how to skip printing 'x' to draw char.


    hope i made u understand my problem
    Last edited by kohlimannu; February 20th, 2006 at 05:39 AM.
    Keep Posting in this Forum

  2. #2
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Problem in C

    Quote Originally Posted by kohlimannu
    I can draw the complete box with the given height and width but problem is how to skip printing 'x' to draw char.

    hope i made u understand my problem
    Unfortunately not. Could you explain more what you mean by "skip printing 'x'"?

  3. #3
    Join Date
    Sep 2002
    Location
    India (Delhi)
    Posts
    199

    Re: Problem in C

    Quote Originally Posted by treuss
    Unfortunately not. Could you explain more what you mean by "skip printing 'x'"?
    actually if give input like this
    Number - 256, Height - 5, Width - 5

    then the output should look like this


    xxxxx
    ......x
    xxxxx
    x......
    xxxxx

    xxxxx
    x.....
    xxxxx
    ......x
    xxxxx

    xxxxx
    x......
    xxxxx
    x....x
    xxxxx
    Keep Posting in this Forum

  4. #4
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: Problem in C

    okey... why would that be a problem ???
    and which 'x' did you wat to skip ????

    now for printing a 2 ....
    - print five 'x'in the first line
    - print an '\n'.......
    - leave four spaces and print another x and \n again
    - print 'x' in first line \n
    - and set of 'x again.

    that should give youv

    xxxxx
    ...... x
    xxxxx
    x
    xxxxx


    similarly u can print all the numbers.
    u can also use setw()

    i hope this is what you were asking???
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  5. #5
    Join Date
    Sep 2002
    Location
    India (Delhi)
    Posts
    199

    Re: Problem in C

    Quote Originally Posted by sreehari
    okey... why would that be a problem ???
    and which 'x' did you wat to skip ????

    now for printing a 2 ....
    - print five 'x'in the first line
    - print an '\n'.......
    - leave four spaces and print another x and \n again
    - print 'x' in first line \n
    - and set of 'x again.

    that should give youv

    xxxxx
    ...... x
    xxxxx
    x
    xxxxx


    similarly u can print all the numbers.
    u can also use setw()

    i hope this is what you were asking???
    Actually the number as u explained 2 is entering by the user so i dont know which number is going to be entered by the user so ive to create it dynamically.
    Keep Posting in this Forum

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Problem in C

    Actually the number as u explained 2 is entering by the user so i dont know which number is going to be entered by the user so ive to create it dynamically.
    Work on generating the numbers with expected values, then generalise the process to work with user input.

    After all, you have to decide things like how should '1' look like, should it be right or left justified etc.

  7. #7
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: Problem in C

    what you willl have to do is write functions for printing these numbers from 0 to 9 .
    and depending on the number that has been entered by the user cal the respective function.

    you could use a switch statement
    Code:
    switch()
    {
    case 1: PrintOne();
                 break;
    case 2: PrintTwo();
                 break;
    ......
    ....
    .....
    }
    now if you are having trouble removing the individual numbers from the num 225

    - after inputing from the user
    loop
    - temp number1 = userEnteredNum % 10 ( that should give you the last
    digit)
    - UserEnteredNumber/10 //repeate this steps till the num cant be divided again. and call the switch statement from the last num that u have stored.... that is start printing from temp Number n ..temp number n-1....till temp number 1...

    end of loop

    kinda crude logic....
    try using char arrays....will help save ya all the trouble of this % 10 thins
    hope this helps ya
    Last edited by sreehari; February 20th, 2006 at 06:59 AM. Reason: error in logic pointed by treuss
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  8. #8
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Problem in C

    Quote Originally Posted by sreehari
    now if you are having trouble removing the individual numbers from the num 225

    - after inputing from the user
    loop
    - temp number = userEnteredNum % 10 ( that should give you the last digit)
    - call the switch statement (so that your number gets printed )
    - UserEnteredNumber/10
    end of loop
    Uhh, that will print the number backwards

  9. #9
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: Problem in C

    Quote Originally Posted by treuss
    Uhh, that will print the number backwards
    Thanks treuss.
    oops...that just sliped out of my mind.
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  10. #10
    Join Date
    Sep 2002
    Location
    India (Delhi)
    Posts
    199

    Thumbs up Re: Problem in C

    THANX ALOT ALL OF U FOR UR HELP
    Keep Posting in this Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured