Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <iomanip>
- #include <climits>
- void buyList(bool item1, bool item2, bool item3);
- void showBalance(int balance);
- int buy(int item, int money, bool item1, bool item2, bool item3);
- int work(bool item1, bool item2, bool item3);
- //bool confirm();
- int main(){
- srand(time(0));
- int choice = 0;
- int item = 0;
- bool item1 = false;
- bool item2 = false;
- bool item3 = false;
- int money = 0;
- int moneyAfter = money;
- int totalMoney = money;
- int sellingItem;
- int hour = 12;
- std::cout << "*************\n";
- std::cout << "Buy Your Bed!\n";
- std::cout << "*************\n";
- std::cout << "In this simple game, you work jobs and get cash! Buy all the items to win!\n\n";
- do{
- if(hour > 1){
- std::cout << "You have " << hour << " hours left to buy your bed!\n";
- }
- else if(hour == 1) {
- std::cout << "You have " << hour << " hour left to buy your bed!\n";
- }
- else{
- std::cout << "You are out of time.\n";
- break;
- }
- showBalance(money);
- std::cout << "1. Buy\n";
- //std::cout << "2. Sell\n";
- std::cout << "2. Work\n";
- std::cout << "3. Exit\n";
- std::cin >> choice;
- std::cin.clear();
- std::cin.ignore(INT_MAX,'\n');
- switch(choice) {
- //Buy
- case 1:
- buyList(item1,item2,item3);
- std::cout << "Choose an item to buy!\n";
- moneyAfter -= buy(item,money,item1,item2,item3);
- if(moneyAfter == money - 50){
- item1 = true;
- money = moneyAfter;
- }
- else if(moneyAfter == money - 200){
- item2 = true;
- money = moneyAfter;
- }
- else if(moneyAfter == money - 500){
- item3 = true;
- money = moneyAfter;
- }
- break;
- //Sell
- /*case 2:
- break;*/
- //Work
- case 2:
- moneyAfter += work(item1,item2,item3);
- totalMoney += work(item1,item2,item3);
- if(moneyAfter > money){
- hour--;
- }
- money = moneyAfter;
- break;
- //Exit
- case 3:
- std::cout << "Leaving early, aren't you? Okay then!\n";
- break;
- default:
- std::cout << "Please choose a valid option.\n";
- break;
- }
- }while(choice != 3);
- std::cout << "\nLet's see the results!\n\n";
- //If Full Set
- if(item1 == true && item2 == true && item3 == true){
- std::cout << "You worked hard and got your full bed! Sleep well!\n";
- }
- //If Quitting Immediately
- else if(money == 0 && item1 == false && item2 == false && item3 == false) {
- std::cout << "Not even trying, are you? Well, good night then...\n";
- }
- //If Only Have Pillow
- else if(item1 == true && item2 == false && item3 == false) {
- std::cout << "At least you got a pillow! Much better than a rock!\n";
- }
- //If Only Have Blanket
- else if(item1 == false && item2 == true && item3 == false) {
- std::cout << "You have a blanket to keep you warm at night! That's still something!\n";
- }
- //If Only Have Mattress
- else if(item1 == false && item2 == false && item3 == true) {
- std::cout << "A mattress is pretty nice! No longer have to sleep on the ground!\n";
- }
- //If Only Have Pillow and Blanket
- else if(item1 == true && item2 == true && item3 == false) {
- std::cout << "Warm and cozy with something to rest your head on! That's good enough!\n";
- }
- //If Only Have Pillow and Mattress
- else if(item1 == true && item2 == false && item3 == true) {
- std::cout << "Something to lay on and support your head! Got the priorities of comfort ready!\n";
- }
- //If Only Have Blanket and Mattress
- else if(item1 == false && item2 == true && item3 == true) {
- std::cout << "Something to cover you and lay on! A pretty good combo!\n";
- }
- //If Nothing Was Bought
- else{
- std::cout << "You worked hard but couldn't get anything for a bed... Time to find a comfy rock!\n";
- }
- std::cout << "\nFinal Money: $" << money << '\n';
- std::cout << "Total Earnings: $" << totalMoney << '\n';
- }
- void buyList(bool item1, bool item2, bool item3){
- if(item1 == false){
- std::cout << "1. Pillow - $50\n";
- }
- if(item2 == false){
- std::cout << "2. Blanket - $200\n";
- }
- if(item3 == false){
- std::cout << "3. Mattress - $500\n";
- }
- std::cout << "4. Back\n";
- }
- void showBalance(int balance){
- std::cout << "Current Cash: $" << balance << '\n';
- }
- int buy(int item, int money, bool item1, bool item2, bool item3){
- int choice1;
- //int choice2;
- //Do loops not work in other functions when called?
- do{
- std::cin >> choice1;
- std::cin.clear();
- std::cin.ignore(INT_MAX,'\n');
- switch(choice1) {
- case 1:
- //choice2 = confirm();
- if (money >= 50 && item1 == false){
- return 50;
- }
- else if(item1 == true){
- std::cout << "Already bought that item.\n";
- return 0;
- }
- else {
- std::cout << "Need more cash!\n";
- return 0;
- }
- break;
- case 2:
- //choice2 = confirm();
- if (money >= 200 && item2 == false){
- return 200;
- }
- else if(item2 == true){
- std::cout << "Already bought that item.\n";
- return 0;
- }
- else{
- std::cout << "Need more cash!\n";
- return 0;
- }
- break;
- case 3:
- //choice2 = confirm();
- if (money >= 500 && item3 == false){
- return 500;
- }
- else if(item3 == true){
- std::cout << "Already bought that item.\n";
- return 0;
- }
- else{
- std::cout << "Need more cash!\n";
- return 0;
- }
- break;
- case 4:
- //choice2 = confirm();
- return 0;
- break;
- default:
- std::cout << "Choose a valid option.\n";
- return 0;
- break;
- }
- }while (choice1 =! 4);
- }
- int work(bool item1, bool item2, bool item3){
- int bonus = 1;
- if(item1 == true || item2 == true || item3 == true) {
- bonus *= 2;
- }
- else if(item1 == true && item2 == true || item1 == true && item3 == true || item2 == true && item3 == true) {
- bonus *=4;
- }
- else if(item1 == true && item2 == true && item3 == true) {
- bonus *=8;
- }
- return rand() % 40 * bonus + (20 * bonus);
- }
- /*
- bool confirm(){
- int choice;
- std::cout << "Confirm?\n";
- std::cout << "1: Yes\n";
- std::cout << "2: No\n";
- do{
- std::cin >> choice;
- std::cin.clear();
- std::cin.ignore(INT_MAX,'\n');
- switch(choice){
- case 1:
- return true;
- break;
- case 2:
- return false;
- break;
- default:
- break;
- }
- }while(choice != 1 || choice != 2);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement