![]() |
| | #1 |
| Registered User Join Date: May 2009
Posts: 32
| help figuring my output problem out Code:
#include <iostream>
#include <string.h>
using namespace std;
class skid{
private://stats are private
int defense;//intilizes variable defense
int strength;//intilizes strength
int health;
string location;
int level;
public:
int attack(){//for use when he "attacks"
skid skid;
skid.strength;
cout<< "You are attacking!";
}
int getdefense() //retrieves defense value from the private part of class
{
cout<< "Defense: " << defense << "\n";
}
int getstrength()//retrieves strength
{
cout<< "Strength: " << strength << "\n";
}
int gethealth()
{
cout<<"Health: " << health << "\n";
}
void getlocation()
{
cout<<"Location: " << location << "\n";
}
int getlevel()
{
cout<<"You are currently level " << level;
}
void getall() //displays all
{
getdefense();
getstrength();
gethealth();
getlocation();
getlevel();
cin.get();
}
int setvalues()
{
defense = 1;
strength = 1;
health = 1;
location = "home";
level = 1;
}
};
int main(){
skid b;
b.setvalues();
b.getall();
}
cj Last edited by jamort; 11-04-2009 at 06:58 PM. |
| jamort is offline | |
| | #2 |
| Registered User Join Date: Jan 2005
Posts: 7,137
| FYI, it should be <string>, not <string.h>. In addition, if you want to improve your work, consider rethinking your get functions. Instead of outputting directly to cout, they should return the value with a return statement. You can then call the functions in a cout statement somewhere else (like in getall() perhaps) and the data will still be output. The benefit is that it is better design, and you will actually be returning a value from functions that are declared to return int. Finally, the code in setvalues is usually done in a constructor. I'm not sure if you've learned those or are supposed to use a set function or if that's just for testing, but consider trying to figure out how to move that code into the constructor so you don't even have to call b.setvalues() inside main. |
| Daved is offline | |
| | #3 |
| Registered User Join Date: May 2009
Posts: 32
| thanks... I think that constuctors are in the next section in the book that im working out of... I was just playing around to see what i could get done right now, and i found out after i posted this that it was just string... Im going to change it to return now |
| jamort is offline | |
| | #4 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| For future reference, blanking some or all of the contents of your post makes the board a lot less useful for people using search engines to look for information. Are you afraid of wasting cboard's disk space?
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #5 |
| Registered User Join Date: May 2009
Posts: 32
| sorry about that lol... used to a forum that deletes your post after your porblem is solved... I'm suprised that i finally got classes though.. I downloaded a video off of youtube and got it in like five minutes for some reason i couldn't get it just reading my book |
| jamort is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Infinite loop output problem | Jonyb222 | C Programming | 5 | 10-08-2009 11:18 AM |
| Problem with my output | Dogmasur | C Programming | 17 | 08-07-2008 08:07 PM |
| output from bank type problem | IzaakF | C Programming | 2 | 09-04-2002 06:42 PM |
| File input output problem | VanJay011379 | C++ Programming | 2 | 08-30-2002 02:09 PM |
| String Output Problem | Yin | C++ Programming | 3 | 03-14-2002 07:36 AM |