help figuring my output problem out

This is a discussion on help figuring my output problem out within the C++ Programming forums, part of the General Programming Boards category; no need to read furthr i figured out my problem but thanks for taking a look Code: #include <iostream> #include ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    106

    help figuring my output problem out

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


    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();
        
    }
    thanks
    cj
    Last edited by jamort; 11-04-2009 at 06:58 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    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
    Posts
    106
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,269
    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?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    106
    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, 12:18 PM
  2. Problem with my output
    By Dogmasur in forum C Programming
    Replies: 17
    Last Post: 08-07-2008, 09:07 PM
  3. output from bank type problem
    By IzaakF in forum C Programming
    Replies: 2
    Last Post: 09-04-2002, 07:42 PM
  4. File input output problem
    By VanJay011379 in forum C++ Programming
    Replies: 2
    Last Post: 08-30-2002, 03:09 PM
  5. String Output Problem
    By Yin in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2002, 07:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21