Click to See Complete Forum and Search --> : Problem in C


kohlimannu
February 20th, 2006, 04:30 AM
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

treuss
February 20th, 2006, 04:42 AM
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'"?

kohlimannu
February 20th, 2006, 05:15 AM
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

sreehari
February 20th, 2006, 05:29 AM
okey... why would that be a problem ???
and which 'x' did you wat to skip ???? :confused:

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???

kohlimannu
February 20th, 2006, 05:37 AM
okey... why would that be a problem ???
and which 'x' did you wat to skip ???? :confused:

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.

laserlight
February 20th, 2006, 05:42 AM
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.

sreehari
February 20th, 2006, 05:45 AM
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

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 :D
hope this helps ya :thumb:

treuss
February 20th, 2006, 05:49 AM
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 loopUhh, that will print the number backwards :)

sreehari
February 20th, 2006, 05:52 AM
Uhh, that will print the number backwards :)

Thanks treuss.
oops...that just sliped out of my mind.

kohlimannu
February 20th, 2006, 06:39 AM
:thumb: THANX ALOT ALL OF U FOR UR HELP