can anyone see why the status.health wont take away the 20 ????

#include <iostream>
#include <string> // To allow use of Strings.
using namespace std;



//char inventoryRequest = 'i';
//Function Definitions.
void displayInventory();
void displayStats();
void statsObject();
void gameOver();
void stats();
void inventory();
void exitGame();
int playGame();

class status{
public://Access Specifier.
	int health;// Attributes.
	int strength;// Attributes.
};

class inventory {
public://Access Specifier.
    float weight; // Attributes.
	int add();// Actions.
	int drop ();// Actions.
};



int main()
{
//Menu Text.
cout<< "\t******Menu******\n\n";
cout<< "Please choose one of the following:\n";
cout<< "1 -Play Game.\n";
cout<< "2 -Exit.\n";


int choice;
cout<< "Choice: ";
cin>> choice;
string name;
switch (choice)
{
//Menu 1 choice.
case 1:
playGame();
break;
//Menu 1 choice.
case 2:
exitGame();
break;
default:
cout<< "That is not a choice!!!\n";
}


getchar();
getchar();
return 0;
}

//Method for play game.
int playGame()
{
status Status = {100,20};
string name;
int age;
char sex;
int choice1;
cout<< "What is your name?\n";
cin>> name;
cout<< "What is your age?\n";
cin>> age;
cout<< "What is your sex, M or F?\n";
cin>> sex;
cout <<"Name:"<< name<<" Age:" << age<< " Sex:"<< sex <<"\n";
cout << "To view your Inventory press i.";
inventory();
cout << "To view your Inventory press s.";
stats();
//Introduction to the Storyline.
cout <<"You are a Roman Soldier in the small town of Udinse."
"\nThere has been rumours that the Viking are coming to find"
"\nand kill the heir to Julias Ceaser in order to unsettle the"
"\nroman soldiers invading scandinavia the Viking territory."
"\nAll Roman Solidiers are filled with anxiety and are ordered" 
"\nby there supieriors to keep watch on these treachorous nights."
"\nIt is also rumoured that the heir to the throne Maxis Aurilias"
"\nCeaser has been hidden in a small Roman town to keep him under" 
"\nthe radar from the Vikings. Even the Soldiers don't know the"
"\nwherabouts of the heir.  Everyone is nervous and fearful of an immediate"
"\nViking attack. It is a cold and windy night on the top of the" 
"\nwatch tower keeping a lookout for unusual activity.  your armour soaked"
"\nand heavy.  Nearly time to finish your shift and go home to bed."
"\nYou walk around the last corner to your house when you see Viking" 
"\nSoldiers raiding house to house.  You are unseen and run to the tower"
"\nto alert the soldiers. The battle goes on for a few hours,"
"\nthe Roman Soldiers being killed off like rats. After standing" 
"\nyour ground in a gruesome fight you are surrounded and ready to die."
"\nSuch a young life,  Only 21. Memories began to flood through your" 
"\nhead like a rapid. The moment of truth.  The Viking edges towards"
"\nyou and raises his blood stained sword and"
	   ".....................";
//Storyline.
cout << "\n\nYou awake, grogey form being struck in the head, tired from"
"\nthe fight the previous night. Back stiff, muscles cramped from the wooden"
"\nfloor below.  You take in your surroundings, your on a ship.  you seem to"
"\nbe in the storage part of the ship.  You get to your feet, and you here a"
"\nvoice you do not recognize nor understand. You are then dragged to up stairs"
"\nand to the hull of the ship.  Waht appears to be the captain takes out his" 
"\nsword........ and goes for one of the crew and then kicks him into the sea." 
"\n you are then dragged to the side of the ship and thrown off."
"\nYou awake on a beach to the sound of wolves, starving and blood hungry," 
"\nthey attack you. You have two choices !!!";
cout<< "\n1 -Run and hope you are fast enough.";
cout<< "\n2 -Take out a weapon and fight.\n";
cin >> choice1;
if ( choice1 == 1)
{
	Status.health - 20;
}
else if(choice1 == 2 )
{
    Status.health- 10;
}
else
{
	cout << "That is not a choice";
}
cout << Status.health ;


cout<< "That was a close call";
        
return 0;
}







//Functions

void exitGame()
{
	cout << "Please press enter to exit the game.";
}


void inventory()
{
	char input[80];
	cin >> input;
	char inventoryRequest[] = "i";
	int invent = strcmp (input,inventoryRequest);
	//compare the player input to inventaryRequest (i) to see if they want to look at inventarty
	if(invent == 0)
	{
	displayInventory();
	}

}

    void displayInventory()
	{
    const int SIZE = 11;
    string inventory[SIZE];
	cout << "******Inventory******\n";
	inventory[0] = "Rock\n";
    inventory[1] = "Stick\n";
	inventory[2] = "Empty\n";
	inventory[3] = "Empty\n";
	inventory[4] = "Empty\n";
	inventory[5] = "Empty\n";
	inventory[6] = "Empty\n";
	inventory[7] = "Empty\n";
	inventory[8] = "Empty\n";
	inventory[9] = "Empty\n";
	inventory[10] = "To continue press Enter.\n";
	cout << "\n" <<endl;
    for (int i = 0; i < SIZE; ++i) {
	
    cout << inventory[i];
	}
    getchar();
	getchar();
	}
	
	
	void stats()
{
	char input[80];
	cin >> input;
	char statsRequest[] = "s";
	int stats = strcmp (input,statsRequest);
	//compare the player input to statsRequest (i) to see if they want to look at inventory
	if(stats == 0)
	{
	displayStats();
	}

}

    void displayStats()
	{
    const int SIZE = 11;
    string stats[SIZE];
	cout << "******Stats******\n";
	stats[0] = "Health\n";
    stats[1] = "\n";
	stats[2] = "Empty\n";
	stats[3] = "Empty\n";
	stats[4] = "Empty\n";
	stats[5] = "Empty\n";
	stats[6] = "Empty\n";
	stats[7] = "Empty\n";
	stats[8] = "Empty\n";
	stats[9] = "Empty\n";
	stats[10] = "To continue press Enter.\n";
	cout << "\n" <<endl;
    for (int s = 0; s < SIZE; ++s) {
	
    cout << stats[s];
    }
    getchar();
	getchar();
	}

	

	void gameOver()
	{
		status Status();
		
		//if (Status.health = 0)
		{
			cout << "Game Over !!!";
		}
	}

Recommended Answers

All 2 Replies

Status.health - 20;

This line makes the processor calculate the value of Status.health - 20.... and then do nothing with the number it has calculated. If you want to change the value of Status.health try

Status.health = Status.health - 20;

Status.health - 20;

This line makes the processor calculate the value of Status.health - 20.... and then do nothing with the number it has calculated. If you want to change the value of Status.health try

Status.health = Status.health - 20;

Thank you it worked :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.