RE: I Need Help With This Vector Problem 08-08-2019, 04:02 AM
#9
(08-07-2019, 08:02 PM)Drako Wrote:(08-07-2019, 08:01 PM)phyrrus9 Wrote:(08-07-2019, 07:59 PM)Drako Wrote: I forgot about this entire thread so I'm sorry for the late response. I'll try and explain what the code is supposed to do, and what the issue is as best as I can.
This code is for a function in my game where a player can scavenge for items in certain locations. And these locations have infection chances. There is also a function that moves the game into a new week (in game week). Once a new week has occurred, I want the infection chances to change. And in my original solution, it doesn't work.
(I modified the code a bit from my original solution so you could understand it better. If you want me to explain my original solution just ask.)
Code:std::vector<int> infectChance = {5, 10, 15, 20, 25, 30, 35, 40, 45}; //List of possible infection chances
std::cout << " 1 > Kin | Location Size: Large | Infection Chance: " << infectChance[0] << "%" << '\n' //Prints everything
<< " Location Description - Kin is the largest location in the region, you'll" << '\n'
<< " probably find lots of loot, but just as many bad guys.\n" << '\n'
<< " 2 > Military Outpost | Location Size: Large | Infection Chance: " << infectChance[1] << "%" << '\n'
<< " Location Description - The government let us down. So does that mean" << '\n'
<< " you can take their stuff now? Hell yes!\n" << '\n'
<< " 3 > Vernal | Location Size: Medium | Infection Chance: " << infectChance[2] << "%" << '\n'
<< " Location Description - A pretty under-developed, rundown town." << '\n'
<< " It's still got stuff though. Maybe.\n" << '\n'
<< " 4 > Mason | Location Size: Medium | Infection Chance: " << infectChance[3] << "%" << '\n'
<< " Location Description - A better more developed Vernal. Go check it" << '\n'
<< " out.\n" << '\n'
<< " 5 > Mavren | Location Size: Small | Infection Chance: " << infectChance[4] << "%" << '\n'
<< " Location Description - OK, lets just make this short and sweet. it's" << '\n'
<< " trailer park. Don't expect a thing.\n" << '\n'
<< " 6 > Return To Bunker\n" << '\n';
well that took forever
out of curiosity, since you're going the inefficient route of using cout, why are you streaming in a newline character instead of just using endl?
I started doing that a while back when I read that endl was actually inefficient. What I read, and also heard from a lot of people was that it flushes and creates a newline. Which is unnecessary.
You'd be correct on it being inefficient, but the entirety of cout is that way. As for flushing the stream though, that's what std::flush is for.