numbers with boxes
-
kbury wrote:
for (int r = 0;r <= rows; r++); { r = r + 1; ... r=r++;
How many times does
r
(andc
) need to be incremented? Also, that rogue semicolon is sure to cause you grief. There's a problem withboxnum
, but it does not affect the box-drawing. I'll withold the answer until you've studied it more."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
changed code to this
<#include <stdio.h> /*Include header*/
#include <stdlib.h>
#include <assert.h>#define mbxhgt 6
#define mbxwid 4int main (void)
{
int rows,
cols,
r = 1,
c = 1,
boxnum = 1,
unit_height,
unit_width;system("cls");
printf ("Mailbox Layout Program\n\n");
printf ("How many rows of mailboxes will there be?");
scanf ("%d", &rows);printf ("\nHow many columns of mailboxes will there be?");
scanf ("%d", &cols);printf ("\n\nThe numbering layout will be:\n");
printf("+---+---+---+---+---+\n|");while (c <= cols)
{c = c + 1; printf (" %d |", boxnum); boxnum = boxnum + 1; }
while (r <= rows)
{r = r + 1;printf ("\\n \\n");
if (boxnum <= 1);
printf("| %d | ", boxnum++);}unit_height = rows * mbxhgt;
unit_width = cols * mbxwid;printf ("\nOverall height of mailbox unit: %d", unit_height);
printf ("\nOverall width of mailbox unit: %d\n", unit_width);return (0);
}/pre>now looks like this:
How many rows of mailboxes will there be?4
How many columns of mailboxes will there be?5
The numbering layout will be:
+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 || 6 |
| 7 |
| 8 |
| 9 |
Overall height of mailbox unit: 24
Overall width of mailbox unit: 20 -
changed code to this
<#include <stdio.h> /*Include header*/
#include <stdlib.h>
#include <assert.h>#define mbxhgt 6
#define mbxwid 4int main (void)
{
int rows,
cols,
r = 1,
c = 1,
boxnum = 1,
unit_height,
unit_width;system("cls");
printf ("Mailbox Layout Program\n\n");
printf ("How many rows of mailboxes will there be?");
scanf ("%d", &rows);printf ("\nHow many columns of mailboxes will there be?");
scanf ("%d", &cols);printf ("\n\nThe numbering layout will be:\n");
printf("+---+---+---+---+---+\n|");while (c <= cols)
{c = c + 1; printf (" %d |", boxnum); boxnum = boxnum + 1; }
while (r <= rows)
{r = r + 1;printf ("\\n \\n");
if (boxnum <= 1);
printf("| %d | ", boxnum++);}unit_height = rows * mbxhgt;
unit_width = cols * mbxwid;printf ("\nOverall height of mailbox unit: %d", unit_height);
printf ("\nOverall width of mailbox unit: %d\n", unit_width);return (0);
}/pre>now looks like this:
How many rows of mailboxes will there be?4
How many columns of mailboxes will there be?5
The numbering layout will be:
+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 || 6 |
| 7 |
| 8 |
| 9 |
Overall height of mailbox unit: 24
Overall width of mailbox unit: 20You are just glutton for punishment, aren't you? As I've said, and demonstrated, you cannot have two separate loops.
kbury wrote:
if (boxnum <= 1);
Other than being unnecessary, do you notice anything wrong with this? My compiler warns me with a C4390 warning.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
You are just glutton for punishment, aren't you? As I've said, and demonstrated, you cannot have two separate loops.
kbury wrote:
if (boxnum <= 1);
Other than being unnecessary, do you notice anything wrong with this? My compiler warns me with a C4390 warning.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
I guess a gluton for punishment. I am new at this and am trying to learn from a online class, which seems to make this more difficult than I had expected.
What's difficult about comparing your code to mine? :confused:
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
You are just glutton for punishment, aren't you? As I've said, and demonstrated, you cannot have two separate loops.
kbury wrote:
if (boxnum <= 1);
Other than being unnecessary, do you notice anything wrong with this? My compiler warns me with a C4390 warning.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
I am using the LCC Win 32 compiler and when I remove the semicolon away from if (boxnum <= 1); It does not print out the 6, 7, 8, 9 at all.
anyways I changed the code and now it does this. Do i need to change the if boxnum statement?
printf ("\n\nThe numbering layout will be:\n");
while (r <= rows)
{ r = r + 1; printf ("\\n \\n");
while (c <= cols)
c = c + 1; printf (" %d |", boxnum); boxnum = boxnum + 1; if (boxnum <= 1); printf(" %d | ", boxnum++); } unit\_height = rows \* mbxhgt; unit\_width = cols \* mbxwid; printf ("\\nOverall height of mailbox unit: %d", unit\_height); printf ("\\nOverall width of mailbox unit: %d\\n", unit\_width);
return (0);
}Mailbox Layout Program How many rows of mailboxes will there be?4 How many columns of mailboxes will there be?5 The numbering layout will be: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Overall height of mailbox unit: 24 Overall width of mailbox unit: 20
-
anyways I changed the code and now it does this. Do i need to change the if boxnum statement?
printf ("\n\nThe numbering layout will be:\n");
while (r <= rows)
{ r = r + 1; printf ("\\n \\n");
while (c <= cols)
c = c + 1; printf (" %d |", boxnum); boxnum = boxnum + 1; if (boxnum <= 1); printf(" %d | ", boxnum++); } unit\_height = rows \* mbxhgt; unit\_width = cols \* mbxwid; printf ("\\nOverall height of mailbox unit: %d", unit\_height); printf ("\\nOverall width of mailbox unit: %d\\n", unit\_width);
return (0);
}Mailbox Layout Program How many rows of mailboxes will there be?4 How many columns of mailboxes will there be?5 The numbering layout will be: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Overall height of mailbox unit: 24 Overall width of mailbox unit: 20
kbury wrote:
while (c <= cols)
For all but the first row, when will
c
ever be LEcols
again? Furthermore, without braces for the innerwhile()
loop, what statements do you expect will be executed?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
kbury wrote:
while (c <= cols)
For all but the first row, when will
c
ever be LEcols
again? Furthermore, without braces for the innerwhile()
loop, what statements do you expect will be executed?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
I am trying to stick to this flowchart given to me. Maybe I just do not understand it. In the flowchart it is only called where I have it in the code and after boxnum it is suppose to go back to col.
Counting this one, I've posted 8 times to this thread, which was 7 times too many. I showed you the answer in my first post. You continue to use your code, which I do not have a problem with, but you still refuse to make the necessary changes or even compare the two to see why they behave differently. I'm confused as to why a person would do this.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Counting this one, I've posted 8 times to this thread, which was 7 times too many. I showed you the answer in my first post. You continue to use your code, which I do not have a problem with, but you still refuse to make the necessary changes or even compare the two to see why they behave differently. I'm confused as to why a person would do this.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Thanks for your help. I tried to code it just like you had in the 1st answer, but my compiler would not compile it.
kbury wrote:
I tried to code it just like you had in the 1st answer...
Using copy & paste?
kbury wrote:
...but my compiler would not compile it.
It was standard C code. What error(s) did you receive?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons