Zombie game script failing

I've been writing a simple text-based zombie survival game. very simple if your experianced. one big concept is meals. when you go out and scavenge, the meals you find will be deposited into your meal inventory. when i do this though, the meals don't deposit, and if your meals go into the negative, you die. so if i collect 9 meals, i'm supposed to be able to stay inside for 9 nights without dying. i will die on the first night.

here is the code... im sorry about posting it all, but my problem (i assume) would be where the random_integer is added to the food. at line 129 (under void scavenge) is my assumed problem. i dont get any errors though!

#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <ctime>

using namespace std;

void Start();
void Die();
void Scavenge();//while scavenging, there is a small chance ur attacked by zombies
void Items();
void Attack();
void Fight();
void Flee(); //you flee, you will lose ALL your supplies, but no chance of dying
void Camp(); //camp acts as a main overveiw
void CampFail();
void Night();//after you do your scavenge or fight. it also updates the game
void Morning();
void Start();
void StartFail();
void WinFight();
void Starve();
void README();

int start;
int choice;
double food;
double random_integer; //newfood is randomized while scavenging
double day;

void main(void)
{
cout<<"\t\t Welcome to Survivalism v1.0.0"<<endl;
cout<<"\t\t To start a new game. Enter 1"<<endl;
cout<<"\t\t To veiw the update log, enter 2"<<endl;
cin>>start;
if
(start == 1)
Start();
else if
(start == 2)
README();
else if
(start > 2)
StartFail();
}
void StartFail(void)
{
cout<<"\t\t What part of enter 1 or 2 did you not understand?"<<endl; //someone fail at typing 1?
cout<<"\t\t Try again, and enter 1 or 2..."<<endl;
cin>>start;
if
(start == 1)
Start();
else if
(start == 2)
README();
else if
(start > 2)
StartFail();
}
void Start(void)
{
cout<<"\t\t You car crashed as you tried to escape from the apocalypse."<<endl;
cout<<"\t\t Now you're stuck in that city..."<<endl;
cout<<"\t\t This game is about you scavenging for food, water, and tools..."<<endl;
cout<<"\t\t Attempt to survive..."<<endl;
cout<<"\t\t You set up camp at an apartment building."<<endl;
cout<<"\t\t And your journy begins..."<<endl<<endl;
Camp();
}
void Camp(void)
{
cout<<" You're at your apartment ''Camp''"<<endl;
cout<<" Enter 1 to check supplies"<<endl;
cout<<" Enter 2 to go scavenge for more supplies"<<endl;
cout<<" Enter 3 to sleep through the day, using up 1 meal"<<endl;
cin>>choice;
if
(choice == 1)
Items();
else if
(choice == 2)
Scavenge();
else if
(choice == 3)
Night();
else if
(choice > 3)
CampFail();
}
void CampFail(void)
{
cout<<" I'm sorry, "<<choice<<" is not valid."<<endl;
cout<<" 1, 2, and 3 are the only valid answers"<<endl;
cout<<" Going back to camp menu..."<<endl<<endl;
Camp();
}
void Items()
{
cout<<" You have "<<food<<" meals"<<endl;
cout<<" To get more, go scavenging."<<endl;
cout<<" Enter 1 to go back to camp"<<endl;
cout<<" Enter 2 to scavenge"<<endl;
cout<<" Enter 3 to sleep"<<endl;
cin>>choice;
if
(choice == 1)
Camp();
else if
(choice == 2)
Scavenge();
else if
(choice == 3)
Night();
else if
(choice > 3)
CampFail();
}
void Scavenge(void)
{
cout<<"Scavenging..."<<endl;
srand((unsigned)time(0));
double random_integer;
for(double index=0; index<20; index++)
random_integer = (rand()%10)+1;
cout<<" You collected "<<random_integer<<" meals."<<endl;
cout<<" You then deposit them into your supplies and go to sleep"<<endl;
food = (food + random_integer);
if (random_integer < day)
Attack();
else if (random_integer > day)
day = day + 1;
food = food - 1;
if(food = 0)
cout<<" You're out of food! Go scavenging."<<endl;
if(food < 0)
Starve();
Morning();
}
void Night(void)
{
cout<<" You relax, taking the day off and watching the dead roam the streets."<<endl;
day = day + 1;
food = food - 1;
if(food < 0)
Starve();
if(food = 0)
cout<<" You're out of food! Go scavenging."<<endl;
Morning();
}
void Morning(void)
{
cout<<" You fell asleep, and woke up alive! You start your next day."<<endl;
cout<<" \t\t Day "<<day<<""<<endl<<endl;
Camp();
}
void Attack(void)
{
cout<<" You wake up to footsteps. Zombies! Fight or Flee?"<<endl;
cout<<" Enter 1 to fight (25% Chance)"<<endl;
cout<<" Enter 2 to flee (Lose all supplies)"<<endl;
cin>>choice;
if
(choice == 1)
Fight();
else if
(choice == 2)
Flee();
}
void Fight(void)
{
srand((unsigned)time(0));
double random_integer;
for(double index=0; index<20; index++)
random_integer = (rand()%10)+1;
if(random_integer < 6)
WinFight();
else if(random_integer > 5)
Die();
}
void WinFight(void)
{
cout<<" You killed the zombie, quietly, and went to sleep."<<endl<<endl;
Camp();
}
void Flee(void)
{
cout<<" You fled to another apartment, losing all your supplies."<<endl<<endl;
food = 0;
Camp();
}
void Die(void)
{
cout<<"\t\t You have died. You survived for "<<day<<" days..."<<endl;
cout<<"\t\t Start new game? Enter 1 for yes, 2 for no"<<endl;
cin>>choice;
if(choice == 1)
main();
else if(choice == 2)
exit(0);
}
void Starve(void)
{
cout<<"\t\t You survived "<<day<<" days."<<endl;
cout<<"\t\t You starved. You ran out of meals."<<endl;
cout<<"\t\t Tip: Don't sleep through your first night."<<endl;
cout<<"\t\t Start new game? Enter 1 for yes, 2 for no"<<endl;
cin>>choice;
if(choice == 1)
main();
else if(choice == 2)
exit(0);
}
void README(void)
{
cout<<"\t\t ==UPDATE LOG=="<<endl;
cout<<"\t\t v1.0.0 - This isn't an update. This is the beginning."<<endl;
cout<<"Starting new game..."<<endl;
Start();
}
Your have a for loop in your Scavenge function. I'm not sure the purpose of it, especially considering it doesn't do anything, so you could remove it. You simply just need to have the one assignment, you don't need to loop it. And your error is the line if(food = 0) because this line assigns your food equal to zero, it doesn't compare like you want it to, and will always return true.

Next time, please use the [code][/code] tags around your code to make it more readable for use please.
thanks, and i will try to
Topic archived. No new replies allowed.