C++ Comparison Not Working

Knight7770

Hippopotomonstrosesquiped aliophobia
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
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
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 The Helper:
    that field is going to explode and though there is competition there is going to be room for all levels in the coming years imho.
  • tom_mai78101 tom_mai78101:
    Why are we competing for rough mornings? :(
  • Varine Varine:
    I don't want to compete for that, yall can have it.
  • Varine Varine:
    @The Helper I'm trying. Once I am more prepared to be figuring out school I'll probably ask for your advice
  • Varine Varine:
    Right now I'm just trying to get through the pandemic and figure out how I'm going to pay for it, and figure out what I need to get a job at Best Buy instead of a kitchen somewhere.
  • thewrongvine thewrongvine:
    oy just catching up on the discussion above. @Varine yeah I usually alternate between claritin & zyrtec, depending on whatever my body decides to reject at the time lol
  • thewrongvine thewrongvine:
    the more I use it the less effective it gets over time as my body accustoms to it so I try to not use it every day
  • S songbird:
    Glad to see some interest in the IS3 NUON reprint. :)
    +1
  • The Helper The Helper:
    Thank you Carl for making that happen that just might be the spark we need.
  • Varine Varine:
    I'm confused and amazed that NUON and TWV's news postings are the things still active.
  • Varine Varine:
    Or Tom Mai, not TWV
  • Varine Varine:
    Whatever happened to Cheshire? Or Firecat, whatever his real name was?
  • Varine Varine:
    I've been using both claritin and fexofenadine or something like that recently alternately and that's been kinda working, I don't feel like my face is going to explode at least. Eyes are still itchy as fuck though
  • tom_mai78101 tom_mai78101:
    I dunno, haven't seen Firecat in a long while now.
  • tom_mai78101 tom_mai78101:
    By the way, we have new file attachment size limits now.
  • Varine Varine:
    Are they bigger?
  • tom_mai78101 tom_mai78101:
    Yeah, new max size limit is 64 MB, to accommodate NUON-Dome emulation.
  • Varine Varine:
    I don't think I ever ran into a file size problem before. What was it before?
  • Varine Varine:
    I've had file type issues before I think, but I haven't uploaded anything since like 2010.
  • The Helper The Helper:
    alot smaller than that basically barely anything and it would have been different then 2010 because of the forum upgrade
  • Varine Varine:
    lol I forgot this used to look different
  • Varine Varine:
    It's by far the brightest webpage I regularly visit, the first thing I usually do is try to figure out dark mode.
  • tom_mai78101 tom_mai78101:
    If you invert the colors, The Helper Forums looks amazing
  • tom_mai78101 tom_mai78101:
    It still has that blue theme at the top
  • Ghan Ghan:
    There's no particular hard limit to attachments. "Something reasonable" is preferred to "a size large enough to fill up the server disk"

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top