Please, help me! :S

This is a discussion on Please, help me! :S within the C++ Programming forums, part of the General Programming Boards category; Please, would you help me? I don`t know why this program doesn`t run. Code: #include <iostream> #include <string>; using namespace ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    8

    Please, help me! :S

    Please, would you help me? I don`t know why this program doesn`t run.
    Code:
    #include <iostream>
    #include <string>;
    using namespace std;
    
    class Item 
    {
    public:
    	Item ()
    	int getPower() const;
    	int getWeight() const;
    	int getName() const;
    
    	void setPower();
    	void setWeight();
    	void setName();
    
    	void read();
    	void print() const;
    		
    private:
    	int power;
    	int weight;
    	char name[256];
    };
    
    void Item::read()
    {
    	cout << "Power: ";
    	cin >> power;
    	cout << "Weight: ";
    	cin >> weight;
    	cout << "Name: ";
    
    		for (int i=0; i < 256; i++)
    
    	cin >> name[i];
    }
    
    void Item::print()
    {
    	cout << "Power: " << power << endl;
    	cout << "Weight: " << weight << endl;
    	cout << "Name: " << name << endl;
    
    
    
    void main ()
    {
    
    	Item Item1;
    
    	Item1.setPower(63);
    	Item1.setWeight(86);
    	Item1.setName(23);
    
    	cout << Item1.getPower() << endl;
    	cout << Item1.getWeight() << endl;
    	cout << Item1.getName() << endl;
    
    	system("PAUSE");
    }

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Use int main() and in the end return 0.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Does it compile? Are you getting errors? If so what are they? Copy and paste them here. I don't see where you've created some of the functions your class is supposed to provide.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    Errors are:
    error C2144: syntax error : 'int' should be preceded by ';' c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 8

    error C2511: 'void Item:: print(void)' : overloaded member function not found in 'Item' c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 40

    fatal error C1004: unexpected end-of-file found c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 62

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Code:
    Item ()
    Missing a ;

    And again...you've not provided an implementation for some of the methods you're trying to use.

  6. #6
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Code:
    void item::print()
    Use ending brackets for this function.

    Also, setPower() is not taking any parameters in the prototype but while calling you are passing a parameter....


    Above all, you didn't define many of functions, atleast not here so that we could see.

    And use int main() and in the end return 0, before ending braces of main()...
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    8

    :)

    Thank you of all!!!

Popular pages Recent additions subscribe to a feed

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