#zybook c++ im so sad

16 messages · Page 1 of 1 (latest)

honest ruinBOT
#

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.

tepid stratus
#

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;
}
sage otter
#

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

tepid stratus
#

would that just be cin >> valCount?

sage otter
#

no valCount is what you're using to loop, don't change that

#

use a different variable

honest ruinBOT
#

@tepid stratus Has your question been resolved? If so, run !solved :)

tepid stratus
#
#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

honest ruinBOT
#

Thank you and let us know if you have any more questions!

tepid stratus