|
-
July 10th, 2007, 12:32 PM
#1
I think this is another problem with strings again
yesterday I went ahead of the strings and made a jump into classes so I am currently experimenting with constructors and destructors. I'm not sure what the problem with the followign code is although i have a feeling it involves the string library.
#include <iostream>
#include <cstring>
using namespace std;
class player
{
private:
int health;
string name;
int hp;
public:
void show ();
construct_player ();
};
player::construct_player ()
{
int new_health; string new_name; int new_hp;
cout << "please enter the name of your new player: \n";
cin >> new_name;
cout << "\n";
cout << "very good " << new_name << " now tell me your health: \n";
cin >> new_health;
cout << "\n";
cout << "last but not least, how much HP would you like to start with: \n";
cin >> new_hp; cout << "\n";
new_health = health;
new_name = name;
new_hp = hp;
}
void player::show ()
{
cout << "here are the stats of your new player: \n\n\n";
cout << health << "\n";
cout << name << "\n";
cout << hp << "\n";
}
int main ()
{
player new_player;
new_player.construct_player();
new_player.show();
return 0;
}
some one please help me correct this code thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|