Hello you guys. Im doing this one homework assignment and i really need some help. This is the problem:

In the grid below, each row/column intersection is a different color. Write an if-statement, possibly including many nested ifs and elses, to assign the right colors to each row and column. In your code, assume variables 'row' and 'col' give the row/col number. Based on the row/col values, assign one value into a char variable 'color', using the letter-abbreviations from the color legend below the grid. If row/col indicates a blank square, then assign no value at all (not even ' ') into 'color'. Don't declare the variables row, col, or color; assume they are already declared. Write just the if-statement described. You may use only as many ifs, elses, nots, ands, and ors as indicated, and may not use any #defines
Use at most the indicated numbers of the following:

* 1 !'s
* 21 &&'s
* 4 else's
* 6 if's
* 5 ||'s

thank you, i really appreciate the help.

How would you write an if statement that excludes the blank space and how would you write an if statement stating that its magenta when its inside the red space with the following guidelines.

This is what ive done so far for the magenta part:

if ((col >= 19 && row < 16 & col >= 21 && row < 18 && col >= 25 && row < 22 && col < 27 && row < 12 && col < 29 && row >= 8) {
color = 'M';
}
else {
if ( col >= 18 && col < 30 && row >= 4 && row < 24)
color = 'R';
}

** see attached file ***

Edited 7 Years Ago by speedy94519: n/a

We don't do your homework for you. What exactly do you want help with.

sorry, don't get the wrong idea, i didn't want you to do my homework I just forgot to put my question and i pressed the button to early. Anyways, my question is how would you write an if statement saying that its magenta when its inside the red square ? how would you suggest about doing that? Ive tried doing this but i dont think its valid to say this:

if ((col >= 19 && row < 16 & col >= 21 && row < 18 && col >= 25 && row < 22 && col < 27 && row < 12 && col < 29 && row >= 8) {
color = 'M';
}
else {
if ( col >= 18 && col < 30 && row >= 4 && row < 24)
color = 'R';
}
where M is magenta and R is Red **see attached file**

if ((col >= 19 && row < 16 & col >= 21 && row < 18 && col >= 25 && row < 22 && col < 27 && row < 12 && col < 29 && row >= 8) {

row < 16 & col >= 21 will not do what you think it will. You probably want to change the '&' to '&&'. Also, your post would typically be posted in the C forum, not in the computer science forum as far as I know. And what is the point of saying things such as "if col >= 19" and then immediately saying "if col >= 21"? If col is >= 21, then clearly, it is also > 19.

This article has been dead for over six months. Start a new discussion instead.