Hello mates.
I am taking my very first programming language (C Programming) and as for practice purposes, I surf sites and try out to make programs. I am having problems with the following C Programming problem.
1) You are required to use at least one for() loop to control the printing of a table in this lab.
2) Do not use the scanf() function in this lab, use the getchar() instead.
3) Your table will consist of three data type representations for each value. The data types are decimal, hexadecimal and the character itself.
4) Present column headers as shown in the output below.
5) Group those three columns together to form one main unit, that unit has to be repeated two more times going horizontally across the screen. After you have printed the unit three times, start a new line.
6) Every twenty lines stop the output and prompt the user to "Hit any key to continue...". Be sure to repeat your column headers again, as shown below.
The range of the table is defined by the two values input by the user at the start of the program.
7) Pay careful attention to how the data in the columns lines up vertically.
8) If the character is between 7 and 13 (inclusive), print the decimal and hexadecimal values only, do not print the character, just print a space instead.
Sample Output
Enter starting character: a
Enter ending character: z
D H C D H C D H C
-----------------------------------------
97 61 a 98 62 b 99 63 c
100 64 d 101 65 e 102 66 f
103 67 g 104 68 h 105 69 i
106 6a j 107 6b k 108 6c l
109 6d m 110 6e n 111 6f o
112 70 p 113 71 q 114 72 r
115 73 s 116 74 t 117 75 u
118 76 v 119 77 w 120 78 x
121 79 y 122 7a z
-------------------------------------------------------------------------------------------------------------------
This is my program so far:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int start;
int end;
int i;
printf("Enter starting character: ");
start = getche();
printf("\nEnter ending character: ");
end = getche();
printf("\n D H C D H C D H C");
printf("\n-------------------------------");
for (i = start; i <= end; i++)
{
while (1)
{
if (start >= 7 && start <= 13)
{
printf("\n%3d %2x", start, start);
}
else
{
printf("\n%3d %2x %c", start, start, start);
}
start = start + 1;
break;
}
}
}
-------------------------------------------------------------------------------------------------------------------
I can give the output right but I can not make it come out in columbs of 3 as it should. Neither do I understand how to break the output after every ouputs.
Help would be appreciated.
Regards
Khizer
I am taking my very first programming language (C Programming) and as for practice purposes, I surf sites and try out to make programs. I am having problems with the following C Programming problem.
1) You are required to use at least one for() loop to control the printing of a table in this lab.
2) Do not use the scanf() function in this lab, use the getchar() instead.
3) Your table will consist of three data type representations for each value. The data types are decimal, hexadecimal and the character itself.
4) Present column headers as shown in the output below.
5) Group those three columns together to form one main unit, that unit has to be repeated two more times going horizontally across the screen. After you have printed the unit three times, start a new line.
6) Every twenty lines stop the output and prompt the user to "Hit any key to continue...". Be sure to repeat your column headers again, as shown below.
The range of the table is defined by the two values input by the user at the start of the program.
7) Pay careful attention to how the data in the columns lines up vertically.
8) If the character is between 7 and 13 (inclusive), print the decimal and hexadecimal values only, do not print the character, just print a space instead.
Sample Output
Enter starting character: a
Enter ending character: z
D H C D H C D H C
-----------------------------------------
97 61 a 98 62 b 99 63 c
100 64 d 101 65 e 102 66 f
103 67 g 104 68 h 105 69 i
106 6a j 107 6b k 108 6c l
109 6d m 110 6e n 111 6f o
112 70 p 113 71 q 114 72 r
115 73 s 116 74 t 117 75 u
118 76 v 119 77 w 120 78 x
121 79 y 122 7a z
-------------------------------------------------------------------------------------------------------------------
This is my program so far:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int start;
int end;
int i;
printf("Enter starting character: ");
start = getche();
printf("\nEnter ending character: ");
end = getche();
printf("\n D H C D H C D H C");
printf("\n-------------------------------");
for (i = start; i <= end; i++)
{
while (1)
{
if (start >= 7 && start <= 13)
{
printf("\n%3d %2x", start, start);
}
else
{
printf("\n%3d %2x %c", start, start, start);
}
start = start + 1;
break;
}
}
}
-------------------------------------------------------------------------------------------------------------------
I can give the output right but I can not make it come out in columbs of 3 as it should. Neither do I understand how to break the output after every ouputs.
Help would be appreciated.
Regards
Khizer
Comment