Initialization Error

Ok,I am currently studying the book Beginning C++ Through Game Programming. The Lost Fortune program is as follows:
-------------------------------------------------
// Lost Fortune
// A personalized adventure

#include <iostream>
#include <string>

using namespace std;

int main()
{
const int GOLD_PIECES = 900;
int adventurers, killed, survivors;
string leader;

//get the information
cout << "Welcome to Lost Fortune\n\n";
cout << "Please enter the following for your personalized adventure\n";

cout << "Enter a number: ";
cin >> adventurers;

cout << "Enter a number, smaller than the first: ";
cin >> killed;

survivors = adventurers - killed;

cout << "Enter your last name: ";
cin >> leader;

//tell the story
cout << "\nA brave group of " << adventurers << " set out on a quest ";
cout << "-- in search of the lost treasure of the Ancient Dwarves. ";
cout << "The group was led by that legendary rogue, " << leader << ".\n";

cout << "\nAlong the way, a band of marauding ogres ambushed the party. ";
cout << "All fought bravely under the command of " << leader;
cout << ", and the ogres were defeated, but at a cost. ";
cout << "Of the adventurers, " << killed << " were vanquished, ";
cout << "leaving just " << survivors << " in the group.\n";

cout << "\nThe party was about to give up all hope. ";
cout << "But while laying the deceased to rest, ";
cout << "they stumbled upon the buried fortune. ";
cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
cout << leader << " held on to the extra " << (GOLD_PIECES % survivors);
cout << " pieces to keep things fair of course.\n";

return 0;
}
-------------------------------------------------------

Now my question is why do I receive an initialization error if I modify the code to: (int survivors = adventurers - killed;) with the rest of the variables. This is how the program looked when I modified it and received the error:
--------------------------------------------------------

// Lost Fortune
// A personalized adventure

#include <iostream>
#include <string>

using namespace std;

int main()
{
const int GOLD_PIECES = 900;
int adventurers;
int killed;
int survivors = adventurers - killed; //why cant i do this?
string leader;


//get the information
cout << "Welcome to Lost Fortune\n\n";
cout << "Please enter the following for your personalized adventure\n";

cout << "Enter a number: ";
cin >> adventurers;

cout << "Enter a number, smaller than the first: ";
cin >> killed;

cout << "Enter your last name: ";
cin >> leader;

//tell the story
cout << "\nA brave group of " << adventurers << " set out on a quest ";
cout << "-- in search of the lost treasure of the Ancient Dwarves. ";
cout << "The group was led by that legendary rogue, " << leader << ".\n";

cout << "\nAlong the way, a band of marauding ogres ambushed the party. ";
cout << "All fought bravely under the command of " << leader;
cout << ", and the ogres were defeated, but at a cost. ";
cout << "Of the adventurers, " << killed << " were vanquished, ";
cout << "leaving just " << survivors << " in the group.\n";

cout << "\nThe party was about to give up all hope. ";
cout << "But while laying the deceased to rest, ";
cout << "they stumbled upon the buried fortune. ";
cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
cout << leader << " held on to the extra " << (GOLD_PIECES % survivors);
cout << " pieces to keep things fair of course.\n";

system("pause");
return 0;
}
-----------------------------------------------
When coded this way the message I receive says that adventurers and killed are being used without being initialized??

Help Please
> int survivors = adventurers - killed; //why cant i do this?
That is not an equation, just simple assignment. Look at the value in the `adventurers' and `killed' variables, and set `survivors' to the result of subtracting them.
The code executes sequentially from top to bottom, at that point you have not set any values to the variables so the compiler mark it as a logic error.
Ok, I get it now. I really appreciate that. I need to pay better attention. Thanks again my friend
Topic archived. No new replies allowed.