Thread: help figuring my output problem out

  1. #1
    Registered User
    Join Date
    May 2009

    help figuring my output problem out

    no need to read furthr i figured out my problem but thanks for taking a look

         #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;
          int attack(){//for use when he "attacks"
              skid skid;
              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
              int setvalues()
                       defense = 1;
                       strength = 1;
                       health = 1;
                       location = "home";
                       level = 1;
    int main(){
        skid b;
    Last edited by jamort; 11-04-2009 at 05:58 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    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.

  3. #3
    Registered User
    Join Date
    May 2009
    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

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    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?
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

  5. #5
    Registered User
    Join Date
    May 2009
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Infinite loop output problem
    By Jonyb222 in forum C Programming
    Replies: 5
    Last Post: 10-08-2009, 11:18 AM
  2. Problem with my output
    By Dogmasur in forum C Programming
    Replies: 17
    Last Post: 08-07-2008, 08:07 PM
  3. output from bank type problem
    By IzaakF in forum C Programming
    Replies: 2
    Last Post: 09-04-2002, 06:42 PM
  4. File input output problem
    By VanJay011379 in forum C++ Programming
    Replies: 2
    Last Post: 08-30-2002, 02:09 PM
  5. String Output Problem
    By Yin in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2002, 06:36 AM
Website Security Test