#Trying to read all values as a whole but code is only outputting based on last value.

7 messages · Page 1 of 1 (latest)

clear pumice
#

for (i = 0; i < numInts; ++i) {
cin >> val;
if (val != -1) {
missingValue = true;
}
else {
missingValue = false;
}
}
if (missingValue) {
cout << "Missing -1" << endl;
}
else {
cout << "Found one or more -1s" << endl;
}
Basically my missingValue is updating after every value and loop cycle so when it gets to the last number it will only print out if that last number is true or false(if it is -1 or not) instead of all my valuesas a whole. How can I get it to read all the inputs as a whole?(It is hw so a for loop is required and basically first day learning for loops so my apololgies for missing this lol.)

quasi templeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

hearty sluice
#

Do you really want to keep reading everything even when you've received a -1? As soon as you get one it seems like you want to stop processing

clear pumice
hearty sluice
#

Well there's two ways of looking at the task. You can look for ALL of the values are ok or ANY of the values -1.

Now think about ALL in terms of logical operations, and then think about ANY, likewise

clear pumice
quasi templeBOT
#

@clear pumice Has your question been resolved? If so, type !solved :)