Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <iostream>
using namespace std;
class Wallet
{
public:
int money;
Wallet()
{
}
void addMoney(int & money, int n)
{
while(n)
{
money++;
n--;
}
}
void getMoney(int & money, int n)
{
while(n)
{
money--;
n--;
}
}
void displayMoney(int & money)
{
if(money==0)
cout<<"you have no money";
else
cout<<"you have "<<money<<" money";
}
}wallet;
int main()
{
int wallet.money=0, a, n, b=1;
while(b)
{
cout<<"Press 1 if you want to add money to your wallet."<<endl;
cout<<"Press 2 if you want to get money out of your wallet."<<endl;
cout<<"Press 3 if you want to see hoe much money you have in your wallet."<<endl;
cin>>a;
switch(a)
{
case 1:{
cout<<"How much money will you add?"<<endl;
cin>>n;
wallet.addMoney(wallet.money,n);
}break;
case 2:{
cout<<"How much money do you want to get?"<<endl;
cin>>n;
wallet.getMoney(wallet.money,n);
}break;
case 3:{
wallet.displayMoney(wallet.money);
}break;
default:break;
}
cout<<"Press 1 if you want anything else."<<endl;
cout<<"Press 0 if you want to exit wallet."<<endl;
cin>>b;
}
return 0;
}