bank_code

 avatar
unknown
c_cpp
2 years ago
2.2 kB
4
Indexable
#include <iostream>
#include <iomanip>
void showbalance(double balance){
    std::cout << "You have " << std::setprecision(2) << std::fixed << balance << " In bank.\n";
}
double depot(double *cash){
    double casha;
    std::cout << "How much cash you will deposit? : ";
    std::cin >> casha;
    std::cin.clear();
    fflush(stdin);
    if (casha > 0 && casha <= *cash){
        *cash -= casha;
        return casha;
    }
    else if (casha > *cash){
        std::cout << "You don't have enough cash to deposit.\n";
        return 0;
    }
    else {
        std::cout << "You not able to deposit that amount.\n";
        return 0;
    }
}
//
double withdr(double *balance){
    double caa;
    std::cout << "How much you will withdraw : ";
    std::cin >> caa;
    std::cin.clear();
    fflush(stdin);
    if (caa > *balance){
        std::cout << "You don't have enough in balance.\n";
        return 0;
    }
    else if (caa < 0){
        std::cout << "That amount is not valid.\n";
        return 0;
    }
    else{
        *balance -= caa;
        return caa;
    }
}
//
int main(){
    double cash = 20000;
    double balance = 1000;
    int choice;
    do{
    std::cout << "------------------------------------------------------------------------------------------------------------------\n";
    std::cout << "What would you like to do?\t\t\t\t\t\t\t\tCash : " << std::setprecision(2) << std::fixed<< cash << std::endl << "1.Show balance\n2.Deposit\n3.Withdraw\n4.Exit\n>> ";
    std::cin >> choice;
    std::cin.clear();
    fflush(stdin);
    switch (choice){
        case 1:
            showbalance(balance);
            break;
        case 2:
            balance += depot(&cash);
            showbalance(balance);
            break;
        case 3:
            cash += withdr(&balance);
            showbalance(balance);
            break;
        case 4:
            std::cout <<"Thank you for using our services!\n";
            return 0;
            break;
        default:
            std::cout <<"Invalid choice.";
    }
    }while (choice != 4);
    return 0;
}
Editor is loading...