Text Game Inventory/Error
Jul 26, 2012 at 5:38am UTC
Okay so I'm making a text based game. I decided to put an inventory in using boolean variables. When I run the program it says that "a function definition is not allowed before '{'." The error is given at the line holding the first open curly brace for the inventory function. Please help Im so confused.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
else if (response == "inventory" )
{
cout << "You have " ;
void inventory()
{
if (steeringwheel == true && rudder == true && fuel == true && flashlight ==true )
{
cout << "a steering wheel, a rudder, fuel, and a flashlight.\n" ;
}
else if (steeringwheel == false && rudder == true && fuel == true && flashlight ==true )
{
cout << "a rudder, fuel, and a flashlight.\n" ;
}
else if (steeringwheel == false && rudder == false && fuel == true && flashlight ==true )
{
cout << "fuel and a flashlight.\n" ;
}
else if (steeringwheel == false && rudder == false && fuel == false && flashlight ==true )
{
cout << "a flashlight.\n" ;
}
else if (steeringwheel == true && rudder == false && fuel == false && flashlight ==false )
{
cout << "a steering wheel.\n" ;
}
else if (steeringwheel == false && rudder == true && fuel == false && flashlight ==false )
{
cout << "a rudder.\n" ;
}
else if (steeringwheel == false && rudder == false && fuel == true && flashlight ==false )
{
cout << "fuel.\n" ;
}
else if (steeringwheel == false && rudder == false && fuel == false && flashlight ==true )
{
cout << "a flashlight.\n" ;
}
else if (steeringwheel == true && rudder == true && fuel == false && flashlight ==false )
{
cout << "a steering wheel and a rudder.\n" ;
}
else if (steeringwheel == false && rudder == true && fuel == false && flashlight ==true )
{
cout << "a rudder and a flashlight.\n" ;
}
else if (steeringwheel == true && rudder == false && fuel == true && flashlight ==false )
{
cout << "a steering wheel and fuel.\n" ;
}
else if (steeringwheel == false && rudder == false && fuel == false && flashlight ==false )
{
cout << "fuel and a flashlight.\n" ;
}
else if (steeringwheel == false && rudder == true && fuel == true && flashlight ==false )
{
cout << "a rudder and fuel.\n" ;
}
else if (steeringwheel == true && rudder == false && fuel == false && flashlight ==true )
{
cout << "a steering wheel and a flashlight.\n" ;
}
else if (steeringwheel == false && rudder == false && fuel == false && flashlight ==false )
{
cout << "nothing.\n" ;
}
}
}
Jul 26, 2012 at 5:57am UTC
Because functions can't reside within any other function. You need to move the function outside of whatever function it resides in, and "Call" the function from within another function to get it to behave correctly.
Topic archived. No new replies allowed.