The following program segment is not supposed to print anything, yet it outputs the first error message, "Error in maximum: 100". What’s wrong, and how would you correct it? Why doesn’t the code output both error messages?
maximum = 75
minimum = 25;
If (maximum = 100)
cout << "Error in maximum: "<< maximum << endl;
If (minimum = 0)
cout << "Error in minimum: "<< minimum << endl;
Okay, so I believe it is because the maximum variable is set at 75. It's an assignment expression and not a logical expression which means that now the maximum has a value of 75 so, the if statement now causes an error. Now, as to why the code doesn't output both error messages, I am a little confused. Is it because it's set to 0?
So the if (maximum = 100) should be if (maximum == 75) since that is the value it was assigned to right? But then why isn't the minimum error coming up? Is it because it's just a 0?
Oh, this isn't a program I wrote. It's just a problem in the book.
I understand putting the logical expression in there (the ==), it's the minimum part that is throwing me off. The question says: why doesn't the code output both error messages? I understand why it would output the error of the maximum, but it's not outputting the minimum.