CSCI 102 - Fall 2023 Fundamentals of Computation

#include <iostream>

using namespace std;

//function prototype, returns double takes two double arguments
double withdraw(double balance, double amount);

//function prototype, returns double takes two double arguments
double deposit(double balance, double amount);

//function prototype, returns bool takes one double arguments
bool isOverdrawn(double balance);

int main()
{
    double balance = 100.0;

    // deposit two paychecks and try to withdraw
    balance = deposit(balance, 500.0);

	//deposits 700 into account and then returns updated balance, calls withdraw passing updated balance and 400 as arguments which   	//returns the updated balance less 400 and then checks if the balance is >=0 by calling withdraw.
	//if isOverDrawn returns false then if executes
    if ( !isOverdrawn(withdraw(deposit(balance, 700.0), 400.0)) )
    {
         balance = withdraw(deposit(balance, 700.0), 400.0); //deposits 700 and then withdraws 400 again and returns updated balance to 	balance variable
    }
    return 0;
}

//function definition, updates balance by subtracting amount withdrawn and returns remaining balance
double withdraw(double balance, double amount) {
    balance -= amount;
    return balance;
}

//function definition, updates balance by adding amount deposited and returns new balance
double deposit(double balance, double amount) {
    balance += amount;
    return balance;
}

//function definition, returns tru if balance is greater than or equal to 0 otherwise returns false
bool isOverdrawn(double balance) {
    return balance < 0.0;
}