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 run !howto ask.
16 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 run !howto ask.
this is my code:
#include <iostream>
using namespace std;
int main() {
int valCount;
bool allNegative;
int i;
cin >> valCount;
for(i=0; i < valCount; ++i) {
if(valCount>= 0) {
allNegative = false;
}
else {
allNegative = true;
}
}
if (allNegative) {
cout << "All match" << endl;
}
else {
cout << "Not all match" << endl;
}
return 0;
}
you need to initialize allNegative as true, and only set the false when something is non negative
also you're just comparing against valCount which doesn't make sense, you need to get the next number and check that
thank you so much for your response. I did everything you said, but did not really understood how to do "get the next number and check"
would that just be cin >> valCount?
@tepid stratus Has your question been resolved? If so, run !solved :)
hi really sorry :(
#include <iostream>
using namespace std;
int main() {
int valCount;
bool allNegative = false;
int x;
cin >> valCount;
for(int i=0; i < valCount; ++i) {
cin >> x;
if(x<= 0) {
allNegative = true;
break;
}
}
if (allNegative) {
cout << "All match" << endl;
}
else {
cout << "Not all match" << endl;
}
return 0;
}
could you tell me what im doing wrong 🥲
!solved
Thank you and let us know if you have any more questions!
thank you so much!! it worked