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;
}

Edited 3 Years Ago by Dani: Formatting fixed

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;
}

Edited 6 Years Ago by VernonDozier: Fixed code tags.

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!

This article has been dead for over six months. Start a new discussion instead.