I have a new question for you and I honestly can't figure out what I am doing wrong. I tried everything I could think of to fix it but I just can't figure it out. When I feed my pet it will go to 11 and then when I try to feed it again it will be where its suppose to be at 10. Why?
This is a copy of what happens when I run the program.
What do you want to name your pet?
snoopy
Your pets name is Snoopy
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
2
1.Feed
2.leave alone
3.Exit
9
I am I'm not hungry
Choose an option:
2
1.Feed
2.leave alone
3.Exit
8
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
9
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
11
I am I'm not hungry
Choose an option:
1
1.Feed
2.leave alone
3.Exit
10
I am I'm not hungry
Choose an option:
This is the program.
#include <iostream> #include <string> std::string GetName(std::string name) { std::string setname; std::getline(std::cin,setname); setname[0] = toupper(setname[0]); return setname; } std::string GetFoodText(int food) { std::string foodmetre; if(food <=0) foodmetre = "Your pet critter dies"; else if(food <=5) foodmetre = "I'm hungry"; else foodmetre = "I'm not hungry"; return foodmetre; } void AddFood(int& food) { if(food < 11) food +=2; } int main() { std::string arr[3] = {".Feed",".leave alone",".Exit"}; std::cout << "What do you want to name your pet?" << std::endl; std::string name; std::string Nam = GetName(name); std::cout << "Your pets name is " << Nam << std::endl; int food = 10; while(food>0) { for(int x = 0; x< 3;x++) { std::cout << x + 1 << arr[x] << std::endl; } std::string foodtxt = GetFoodText(food); std::cout << food << std::endl; std::cout << "I am " << foodtxt << std::endl; int choice; std::cout << "Choose an option:" << std::endl; std::cin >> choice; if(choice == 1) { //food +=2; AddFood(food); } else if(choice == 3) { break; } food--; } }