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.)
#Trying to read all values as a whole but code is only outputting based on last value.
7 messages · Page 1 of 1 (latest)
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.
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
Well I know the hw terminal when I submit reads every input, I assume to check I’m looping properly as that’s the topic of this assignment also I can’t edit or change or add to the last if else statement
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
Thank you man, I’ll see if I can figure it out with that
@clear pumice Has your question been resolved? If so, type !solved :)