18
« on: May 10, 2006, 06:01:20 pm »
// Gold Fish Feeding Simulator
// Another Ranom Product from Vortex Inc.
// Wait, hold on, I could turn this into a game...
#include <iostream> // What we have to do to be able to show anything.
using std::cout; // This is how we show things.
using std::cin; // This is how we get things to influence our show things.
#include <iomanip> // No idea, going to have to read my C++ book again. And maybe finish it. >.>
using std::setw;
#include <cstdlib> // I THINK this is for something random.
#include <ctime> // I know this is the time function that we use for true randomness.
int main() // The main program, this is what determines what we see.
{ // I got this far and then I realized game potential. >.>
enum Status { CONTINUE, LOST, SSSS }; // Enumeration for the game status.
int aFeed; // This is the amount you feed the gold fish on your turn.
int aTake; // This is the amount the gold fish can take total, it's seperate because I don't want it to
// randomize each turn.
int rTake; // What I'll use to determine how much it can take. It will get a random amount, and that aTake will
// Recieve it's value.
int hTake; // This is how much the goldfish has already taken. When this is equal to or above aTake, the goldfish
// will... err... explode. >.>
int cTake; // How much the player enters in the while loop, this is added to hTake.
int aNeed; // You still have to feed the gold fish enough. This is the non-random part.
int rNeed; // This is the random variable from which aNeed gets it's value.
Status game;
srand( time( 0 ) ); // I'm using this to make the amount random.
rNeed = ( 20 + rand() % 25 ); // Find out how much the gold fish needs.
aNeed = rNeed; // Assign the value to aNeed.
rTake = ( 24 + rand() % 26 ); // Find out when the gold fish will explode.
aTake = rTake; // Assign the value to aTake.
cout << "Gold Fish Feeding Game!\n"; // The title.
cout << "Feed the gold fish enough food to survive, but \n"; // Instructions.
cout << "Don't overfeed it or it will explode!\n"; // Some more instructions.
cout << "When it asks you, enter how much food you feed the goldfish.\n"; // Instructions.
cout << "Enter 7777 to not feed the goldfish any more.\n"; // How to break out of feeding.
cout << "\n"; // To put some space in between the game and the instructions.
cout << "How much will you feed the fish?\n"; // First prompt.
cin >> hTake; // Give hTake the value of the amount.
game = CONTINUE; // Do this so we don't skip the while loop.
while ( game == CONTINUE ) { // The while loop.
cout << "How much more will you feed the fish?\n"; // The second occurence of the prompt.
cin >> cTake; // The player enters the amount.
if ( cTake == 7777 )// If the player wants to stop feeding the fish...
game = SSSS;
else
hTake + cTake; // Add the amount of cTake to hTake.
if ( hTake >= aTake )
game = LOST;
}
if ( game == LOST )
cout << "Oh no! You exploded the fish! Now \nLittle Joey will throw a tempertantrum.\n"; // Tell the player it exploded!
else if ( game == SSSS ) { // I'm using an else if so that I can have an error message option.
if ( hTake > aNeed ) // If you fed the fish enough...
cout << "You fed the fish enough and it survived! Yaayyy!\n"; // Give a victory message.
else // Otherwise...
cout << "You didn't feed the fish enough and it died. \nShame on you!\n"; // The fish died! Punish the player!
}
else // If the game isn't experiencing either of these options, we have a problem.
cout << "This game has had an unexpected error\n and needs to close.\n"; // Give the error message.
system("PAUSE"); // Allow the player to read the message he got before closing.
return 0; // Signal success.
} // End the program. That's it, folks!
Oklay, I think everything else is going fine, but when I put in an amount I know is enough for the fish, it still says I didn't feed it enough. I know I fed it enough because I temporarily made hte variable of how much it needs a certain amount (22). Any suggestions? Comments? Code that would optimize the game but is cryptic to me?