I was trying to make a bank program in C++, where you can view the amount of money in your wallet, and in your bank account, and deposit and withdraw money. when I try to run it, it lets me input, but when i input anything, it repeats Money in Wallet: 20
again and again and again until I get stack overflow, which I thought was kind of ironic, posting this on a website called Stack Overflow.
This is my code so far:
#include <iostream>
using namespace std;
float money= 20.00;
float account=100.00;
float amount;
bool cmd;
void wallet()
{
cout<<"Money in Wallet: "<<money<<endl;
}
void bank()
{
cout<<"Money in Bank: "<<account<<endl;
}
void deposit()
{
cout<<"How much do you want to deposit?: ";
cin>>amount;
if (money>=amount)
{
account = account+amount;
money = money-amount;
}
else
{
cout<<"You don't have enough money!\n";
}
}
void withdraw()
{
cout<<"How much do you want to withdraw?: ";
cin>>amount;
if(account>=amount)
{
money = money+amount;
account = account-amount;
}
else
{
cout<<"There isn't enough money in your bank account!\n";
}
}
void prompt()
{
cmd="null";
cout<<">";
cin>>cmd;
if (cmd="wallet")
{
wallet();
cmd="null";
prompt();
}
else{
cout<<"Unknown Command.";
cmd="null";
prompt();
}
if (cmd="bank")
{
bank();
}
else{cout<<"Unknown Command.";}
if (cmd="deposit")
{
deposit();
}
else{cout<<"Unknown Command.";}
if (cmd="withdraw")
{
withdraw();
}
else{cout<<"Unknown Command.";}
}
int main()
{
prompt();
}
Please help!