Except now it is just terminating every time.
Here is my code: Code:
#include<stdio.h> |
Quote:
Prove it ! Tell us the page number(s) and copy-paste the paragraphs justifying the piece of code in red. |
Good thing I figured it out so that doesn't even matter anymore. And I wasn't the one who came up with "s/h/f" just to let you know.
|
Uh, I'm not so sure it looks fine to me ;)
Code:
#include <stdio.h> Quote:
Out of curiousity, what do the values (codes? abbreviations?) "s", "h" and "f" mean? Or why is the variable "row" named "row"? I don't understand how you're using it as a row (or are you?) |
s, h, and f stand for the type of shape that the user wants printed. For example, s stands for straight line, h stands for half tip and f stands for full tip. And I named "row" "row" because it is the value of the number of row of the shape to be printed and it's easier to keep track of it that way.
|
Quote:
You stubbornly refuse to get knowledge from the ultimate source of it. |
Quote:
|
Back in post 49 I said that "the if conditional needs to be broken down into three parts: is it a 's' or is it a 'h' or is it a 'f'. Often it is easier to consider the positive outcome (was a valid value entered) rather that the negative outcome (was an invalid value entered). The negative outcome will be part of the else statement."
Your code has progressed from: Code:
if(shape!=s/h/f) Code:
if(shape!='s'||'h'||'f') Looking at the logic problem if shape has the value 'x' then the three terms evaluate to: "true or true or true" which is true and is what is required. Now what happens if shape has the value 's'? The expression evaluates to "false or true or true" which evaluates to true. To fix the logic problem you need to change the ors to ands giving in English: "if shape doesn't equal 's' and shape doesn't equal 'f' and shape doesn't equal 'h'" |
Thank you, graemef. That's what I tried to illustrate. Let's put my code and your explanation together for boilers696, shall we?
Code:
/* SAMPLE I GAVE ABOVE: WHY "||" SYNTAX IS WRONG! */ Quote:
Code:
/* POSSIBLE CORRECTION */ Code:
/* BETTER CORRECTION */ |
Quote:
Code:
if(shape!='s'||'h'||'f') |
I finished it. Thanks for the help.
|
boilers969 -
Glad you got things working. But for whatever it's worth, Sergei Steshenko is absolutely correct. As you'll undoubtedly learn if you continue working with software ... it's very easy for a program to *appear* to work OK ... and yet have it fail completely once it leaves your hands. It's far, far less important for a program to "run" than it is for you to UNDERSTAND the program. Inside and out. Here's a short article that might help explain better: http://www.pragprog.com/the-pragmati...ts/coincidence Sincerely .. PSM |
All times are GMT -5. The time now is 07:56 AM. |