Hi, so I have my program almost complete, it's supposed to draw a hollow box from one number input in a range of 3-50. For some reason when I input a number it has two prompts and then does the calculations, in other words I have to put in a number twice for it to actually do anything. I suspect it has something to so with my top while loop but I can't find the problem. I've re-read my book but it doesn't cover much about excluding certain characters very well. The idea of the while loop after the do loop is to catch any non-number input. I couldn't find any posts on how to format my code nicely but I'll just copy/paste for now.
Wow! it works now, that bit of code "(cout << "Side size = "," seems like such a small addition to the code, I'm not sure how it works. To me all that's saying is while "cout << side..." is true print it out, and it can always be true. So, how is this one statement so important?
I just came across this trying to google that code you gave me. (I'm surprised I found the exact same problem through google by the way). Basically !(cin >> size)) is acting as another prompt!
That's weird that it dumps the previous values before the comma. Maybe it's just to save memory? So in the while loop you provided, the fist expression is always true? how does it still print out if it's discarded when it gets to !(cin >> size))? and then the last expression is always true as long as I put in a non-number? That's how my program behaves anyway...
A discarded-value expression is an expression that is used for its side-effects only. The value calculated from such expression is discarded. Such expressions include the full expression of any expression statement, the left-hand operand of the built-in comma operator, or the operand of a cast-expression that casts to the type void. https://en.cppreference.com/w/cpp/language/expressions#Discarded-value%20expressions
In the expression statement std::cout << "hello world" ;, the expression std::cout << "hello world" is a discarded-value expression. It is evaluated and its side-effect is that something is printed out on stdout, but its result is discarded.
> and then the last expression is always true as long as I put in a non-number?