Permalink
Cannot retrieve contributors at this time
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?
Text-based-Game/money.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 lines (65 sloc)
1.3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |