C++ Comparison Not Working

Knight7770

Hippopotomonstrosesquiped aliophobia
Reaction score
187
Once again, I am at a loss for how to fix this comparison not working. The compiler doesn't give me any errors, but it is obvious that the comparison does not work. Here is the code:

The comparison:
Code:
if(total_stocks[0]<objective||total_stocks[1]<objective||total_stocks[2]<objective||total_stocks[3]<objective||total_stocks[4]<objective||total_stocks[5]<objective||total_stocks[6]<objective||total_stocks[7]<objective||total_stocks[8]<objective||total_stocks[9]<objective)

The setting of total_stocks[]:
Code:
for(int a=0;a<iPlayers;a++)
	{
		total_stocks[a]=cookies[a]+muffins[a]+pies[a]+cakes[a];
		std::cout<<total_stocks[a]<<"\n";
	}

The else to match the if:
Code:
else{
		std::cout<<"You win! Yay!\n";
		return 0;
	}

The setting of objective:
Code:
std::cout<<"How many stocks would you like to reach in order to be victorious? (Enter a negative number to play continuously)\n";
	std::cin>>objective;

The problem is that the if statement always seems to be true. I even output total_stocks[] to make sure that it's greater than objective, and even when it is, the if statement always seems to be true.
If you need more code, just ask.
Thanks :thup:
 

enouwee

Non ex transverso sed deorsum
Reaction score
239
I'd rather use something like this:
Code:
for (i = 0; i < iPlayers; i++)
{
  if ((cookies[i] + muffins[i] + pies[i] + cakes[i]) >= objective)
  {
    std::cout<<"You win! Yay!\n";
    return 0;
  }
}

But you should better post the whole code, if everything is like the few lines you posted, you've got a pretty bad mess there. I'm not surprised at all it doesn't work. :rolleyes:
 

Knight7770

Hippopotomonstrosesquiped aliophobia
Reaction score
187
I'd rather use something like this:
Code:
for (i = 0; i < iPlayers; i++)
{
  if ((cookies[i] + muffins[i] + pies[i] + cakes[i]) >= objective)
  {
    std::cout<<"You win! Yay!\n";
    return 0;
  }
}

But you should better post the whole code, if everything is like the few lines you posted, you've got a pretty bad mess there. I'm not surprised at all it doesn't work. :rolleyes:
Your code seems to have fixed it :D
At least now you don't have to trouble yourself with reading my mess of code; thanks :thup:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top