Quote:
|
Originally Posted by bostero22
double temperature;
char Q, q;
while (temperature != 'Q' || temperature != 'q')
{
|
- It is a bad idea to test for a condition without either initializing or assigning the value which is being tested. You are banking on the fact temperature is not 'Q' or 'q'.
- Secondly, temperature is defined as a double. What do you expect will happen if a char is assigned?
- Lastly, given that you are doing a number of computations before wanting to break out of the loop, this is situation in which a do-while loop is warranted:
#include <iostream>
using namespace std;
int
main() {
char c;
do {
int i;
cout << "input integer value: ";
cin >> i;
cout << i << " was received. Continue?";
cin >> c;
} while (tolower(c) != 'q');
return 0;
}
Lastly, when questions like this come up
(& they come up for everybody...), take the time to reduce the problem down to the smallest case which still duplicates the same problem. If the fix isn't evident, you will have a clearer understanding of what still needs to be resolved.