My First build simple Game

Well this is my second serious program(game) build by me, i know isn't very much but this game is a big step for me , nothing for you but whatever , what is your opinion about it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  #include <iostream>

using namespace std;

int main()
{
    char eng1;
    int mng1 = 200;
    char eng2;
    int mng2 = 0;
    char eng3;
    int mng3 = 500;
    int module1 = 0;
    int mng0 = 75;
    int credit = 0;
    credit++;
    cout << "WELCOME TO THE MONEY MAKER! PLEASE ENTER YOUR FIRST LETTER FROM YOUR NAME!" << endl;
    cin >> eng1;
    cout << "HELLO " << eng1 << " THIS ARE YOUR MONEY: " << mng1 << " YOU HAVE TO PAY A TAX EVERY DAY!,YOU NEED TO MAKE MANY MONEYS HOW MUCH IS POSSIBLE!" << endl;
    cout << "PLEASE WRITE THE LETTER [s] TO START" << endl;
    cin >> eng2;
    switch(eng2)
    {
    case 's':
        while (mng2 <= 3)
        {
            cout << "DEBT :" << mng3 << endl;
        cout << "YOU HAVE PAID 50$ TO DEBT" << endl;
        mng1-=50;
        mng3-=50;
        cout << "YOUR MONEYS: " << mng1 << endl;
        cout << "WRITE [w] TO GO TO WORK,OR [n] TO DON'T GO" << endl;
        cin >> eng3;


        switch(eng3)
        {
        case 'n' :
            {
              cout << "YOU DIDN'T WENT TO THE JOB" << endl;
              break;
            }

        case 'w' :
            mng1+=mng0;
            cout << "YOU HAVE WON " << mng0 <<endl;
            module1++;

            while (module1 == 3)
        {
            cout << "SOMETHING WENT WRONG, AND YOU LOST SOME MONEYS, AND THE DEBT JUST RAISED WITH 100$ FOR SOME REASONS!" << endl;
            mng1-=100;
            mng3+=100;
            cout << "AND MORE WORST , YOUR BOSS JUST START TO GIVE YOU LESS MONEY BECAUSE, WHY NOT?" << endl;
            mng0-=10;
            cout << "P.S , THANKYOU FOR PLAYING ;)" << endl;
            break;
        default:
            cout << "ERROR, PLEASE WRITE [d] TO TRY AGAIN" << endl;
            cin >> eng2;
        }
            break;
        }

        if (mng1 == 0)
        {
            cout << "GAME OVER , YOU BANKRUPT!" << endl;
            break;
        }
         else if (mng3 == 0)
         {
             cout << "YOU WON THE GAME" << endl;
             cout << "THANKS FOR PLAYING , THIS GAME WAS CREATED BY (Andreiz112dn)" << endl;
             cout << "NOW THE CREDIT :)" << endl;
             cout << "BUILD/TESTED/ETC by Andreiz112dn" << endl;
             break;

         }
        }
    }
    return 0;
}
Last edited on
what is your opinion about it

On the whole, it’s nice.

Seemingly you want the working daily fee to be decreased by 10 every 4 days, repeatedly. Your loop doesn’t manage that in a proper way.

I’d prefer to use more meaningful names for my variables, to remember what I need them for while I’m writing the code, but that’s personal.

I also find declaring all variables in a bunch at the beginning of a function deceptive. I think you’d better not to declare a variable until you really need it. For example, I think your variables “mng2” and “module1” were originally declared for the same purpose, i.e. they are two duplicates.
I think your variable “credit” is pointless as well.

Using ‘switch’ to manage a single case make the code harder to read, in my opinion: I’d prefer a simpler ‘if’ in such a case.

Finally, I think you have put inside your while-loop code that should be executed only after the loop has terminated.

Here are some hints about what I’ve written above:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>

int main()
{
    std::cout << "Welcome to the Money Maker!\nPlease enter your first letter "
                 "of your name: ";
    char pl_name;
    std::cin >> pl_name;

    int pl_money = 200;
    std::cout << "Hello, " << pl_name << ", this is your money: " << pl_money
              << "\nYou have to pay a tax every day, so you need to make as "
                 "much money as you can!\n"
                 "Please write the letter [s] to start... ";
    char opt_out;
    std::cin >> opt_out;

    // If user doesn't press 's', simply exit
    if('s' != opt_out) {
        std::cout << "See you soon on Money Maker!\n";
        return 0;
    }

    int luckydays = 0;
    int debts = 500;
    int fee = 80;
    while (pl_money > 0 && debts > 0)
    {
        char work = '\0';
        while(work != 'n' && work != 'w')
        {
            std::cout << "\nWrite [w] to go to work or [n] not to go: ";
            std::cin >> work;
            switch(work)
            {
            case 'n' :
                std::cout << "You didn't go to work.\n";
                break;

            case 'w' :
                pl_money += fee;
                std::cout << "You have earned " << fee << '\n';
                luckydays++;

                if (luckydays > 3)
                {
                    luckydays = 0;
                    pl_money -= 100;
                    debts += 100;
                    fee -= 10;
                    std::cout << "\nSomething went wrong:\n  - You lose some money!\n"
                                 "  - Your debts rise in 100$ for some reasons!\n"
                                 "  - And, moreover, your boss starts to give you less "
                                 "money because, why not?\n"
                                 "P.s. thank you for playing ;)\n\n";
                }
                break;

            default:
                std::cout << "Error. Please try again.\n";
                break;
            }
        }                                           // end while(work...)

        pl_money -= 50;
        debts -= 50;
        std::cout << "You have just paid 50$ to debts..."
                     "\nYour money: " << pl_money
                  << "\nYour debts: " << debts << '\n';
    }                                               // end while(pl_money > 0...)

    // If we get here, either pl_money or debts has gone below zero
    if (pl_money <= 0) { std::cout << "\nGAME OVER, YOU BANKRUPT!\n"; }
    else if (debts <= 0)
    {
        std::cout << "\nYOU WON THE GAME!\n"
                     "\nThanks for playing; this game was created by (Andreiz112dn)"
                     "\nNow the credit :)\nbuild/tested/etc by Andreiz112dn";
    }

    return 0;
}


Happy coding!
Topic archived. No new replies allowed.