Here are the two functions that I'm trying to get to work together. Anyone know how to call my overDraft function into my withdraw function if statement? Thanks.

bool withdraw(double amt, int pin){
    if (amt <= bal)
        return true;
    if(amt >= bal)
            return ????; //Need this to call my overdraft function from below??


}
bool overDraft(int pin){
    if (pin ==123)
            return true;
        if(pin==456)
            return false;
        if(pin==789)
            return true;
}

Recommended Answers

All 3 Replies

Please use code tags:

[code]

// code here

[/code]


Try this.

bool withdraw(double amt, int pin){
    if (amt <= bal)
        return true;
    if(amt >= bal)
        return overDraft(pin);
}


bool overDraft(int pin){
    if (pin ==123)
        return true;
    if(pin==456)
        return false;
    if(pin==789)
        return true;
}

I get this error.

error C3861: 'overDraft': identifier not found

The compiler has to know that a function called "overDraft" exists before it gets to a line that calls that function. There are two options:

1) you can declare that the function exists by putting a "prototype" of the function before "withdraw". The prototype for overDraft has to exactly match the function definition (but parameter names can be omitted) as follows:

bool overDraft(int pin); //prototype of overDraft, to put before withdraw

2) Just invert the order of the two functions:

bool overDraft(int pin){
    if (pin ==123)
        return true;
    if(pin==456)
        return false;
    if(pin==789)
        return true;
}

bool withdraw(double amt, int pin){
    if (amt <= bal)
        return true;
    if(amt >= bal)
        return overDraft(pin);
}

Enjoy!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.