[C++] Need help regarding classes menu

User Tag List

Results 1 to 3 of 3
  1. #1
    klamor's Avatar Active Member
    Reputation
    30
    Join Date
    Mar 2007
    Posts
    323
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [C++] Need help regarding classes

    Ok, so basically i'm trying to call a function of a class within another function of that same class. If anybody could help me I would really appreciate it

    Code:
    #include<iostream>
    using namespace std;
    
    class Hugeint
    {
        int hint[4][4];
    
    public:
        Hugeint();
        void display();
        void add(int,int);
        int convert(int,int);
    };
    
    Hugeint::Hugeint()
    {
        int placeholder[4]={1,2,3,4};
        for(int x=0; x<4; x++)
        {
            for(int y=0; y<4; y++)
            {
                hint[x][y]=placeholder[x];
            }
        }
    }
    
    void Hugeint::display()        //Displays the array in two dimensions.
    {
        for(int x=0; x<4; x++)
        {
            for(int y=0; y<4; y++)
            {
                cout<<hint[x][y];
            }
            cout<<endl;
        }
    }
    
    void Hugeint::add(int num1,int num2)    //Calls convert function for both numbers to get in int form, then adds.
    {
        int n1, n2, first, second, sent, total;
        n1 = num1+1;
        n2 = num2+1;
        sent = n1;
        first = h1.convert(sent);
        sent = n2;
        second = h1.convert(sent);
        total = first+second;
        cout<<total<<endl;
    
    }
    
    int Hugeint::convert(int sent)//Converts the numbers chosen in from hint into ints respectively.
    {
        int int1=0;
        for(int pnt=0; pnt<4; pnt++)
        {
            for(int zeros=3; z<=0; z--)//How many zeros to add based on the placement of the number.
            {                           //4321 = 4000 + 300 + 20 + 1
                if(zeros==3)
                    int1=int1+(hint[sent][pnt]*1000);
                if(zeros==2)
                    int1=int1+(hint[sent][pnt]*100);
                if(zeros==1)
                    int1=int1+(hint[sent][pnt]*10);
                if(zeros==0)
                    int1=int1+hint[sent][pnt];
            }
        }
        return int1;
    }
    
    int main()
    {
        int num1, num2;
        Hugeint h1;
        h1.display();
        system("PAUSE");
        cout<<"What would you like add?"<<endl;
        cin>>num1;
        cout<<' ';
        cin>>num2;
        h1.add(num1,num2);
        return 0;
    }
    In the function "void Hugeint::add()" I'm getting an error that states "h1 - undeclared ifentifier".


    [C++] Need help regarding classes
  2. #2
    [Blinded]'s Avatar Contributor
    Reputation
    88
    Join Date
    Nov 2009
    Posts
    177
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use this->(class function) or you leave it out ... ( in your Classfunctions )
    NO h1.
    Last edited by [Blinded]; 10-15-2010 at 03:12 AM.

  3. #3
    Swiftle's Avatar Member
    Reputation
    2
    Join Date
    Jun 2008
    Posts
    48
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have several errors. First you have:

    Code:
    first = h1.convert(sent)
    h1 isn't declared in this scope and secondly convert requires 2 parameters.

Similar Threads

  1. Need help! Regarding a Spell Swap (DBC)
    By toby in forum WoW ME Questions and Requests
    Replies: 0
    Last Post: 02-23-2009, 04:47 PM
  2. [Help] Regarding the 2.4 ( Need some Info to create a Dll )
    By ~SaiLyn~ in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 03-26-2008, 04:24 PM
  3. Need Help To Choose Race/class/faction!
    By Wizardhound in forum World of Warcraft General
    Replies: 25
    Last Post: 03-01-2008, 08:46 AM
  4. Need help ASAP (regards scammed account)
    By uberhak3r in forum World of Warcraft General
    Replies: 7
    Last Post: 06-21-2007, 12:01 AM
All times are GMT -5. The time now is 07:38 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search