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!