#basic error(coudnt figure out)

12 messages · Page 1 of 1 (latest)

fierce zodiac
#

hi there, im trying to use public functions to access private functions but have failed a little.

white dockBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

fierce zodiac
#
#include <string>

using namespace std;

class binary
{
    string s;

public:
    void read(void);
    void chk_bin(void);
    void once_compliment(void);
    void display(void);
};

void binary :: read(void) {
    cout << "enter a binary number" << endl;
    cin >> s;
}

void binary :: chk_bin(void) {
    for(int i = 0; i < s.length(); i++) {
        if(s.at(i) != '0' && s.at(i) != '1') {
            cout << "incorrect binary format" << endl;
            exit(0);
        }
    }
}

void binary :: once_compliment(void) {
    for(int i = 0; i < s.length(); i++) {
        if(s.at(i) != '0') {
            s.at(i) = '1';
        }
        if(s.at(i) != '1') {
            s.at(i) = '0';
        }
    }
}

void binary :: display(void) {
    cout << "displaying binary number";
    for(int i = 0; i < s.length(); i++) {
        cout << s.at(i);
    }
}

int main() {
    binary b;
    b.read();
    b.chk_bin();
    b.once_compliment();
    
    return 0;
}
#

working well

#

but isnt asking for input of the string

wild shale
fierce zodiac
#

so we basically used that input as a string to execute the code further

#

thanks a ton

wild shale
#

I did nothing but yw

fierce zodiac
#

!solved