ARTICLE AD BOX
just started programming a week ago and learned enough to write a simple text-based game. i was wondering if its "clean code" or would it be considered messy? some variables are defined in other files but all i want to know is if the main file is clean. i heard its not a good idea to nest if statements but i really dont know how else to put em. this is all in c++
#include <iostream> #include <string> #include "bigtxt.h" using namespace std; int main() { string item2 = "nothing"; string item3 = "nothing"; string item4 = "nothing"; string item5 = "nothing"; string item6 = "nothing"; string item7 = "nothing"; string item8 = "nothing"; string item9 = "nothing"; srand(time(NULL)); //declaring random number generator 1 int randmnumber = (rand() % 3) + 1; int funmeter = 0; int morelikely = (rand() % 10) + 1; int userinput; if (randmnumber == 1) { // this is like. toby fox's game fun meter 2 funmeter = funmeter + 5; // 5 is hardest difficulty } else if (randmnumber == 2) { funmeter = funmeter + 10; // mid difficulty } else { funmeter = funmeter + 15; // easiest difficulty } cout << bigtxt; // INTROSCENE cin >> userinput; } switch (userinput) { // players items case 2: cout << item6; break; case 3: cout << item7; break; case 4: cout << item8; break; case 5: cout << item9; break; case 6: cout << item6; break; case 7: cout << item7; break; case 8: cout << item8; break; case 9: cout << item9; break; } if (funmeter == 5) { // first choice -- hardest difficulty if (userinput == 0) { if (morelikely <= 3) { cout << creaturesceneA; cin >> userinput; } else { cout << creaturesceneB; cin >> userinput; } } else if (userinput == 1) { if (morelikely <= 3) { cout << darknesssceneA; cin >> userinput; } else cout << darknesssceneB; cin >> userinput; } } if (funmeter == 10) { // first choice -- medium difficulty if (userinput == 0) { if (morelikely >= 5) { cout << creaturesceneA; cin >> userinput; } else { cout << creaturesceneB; cin >> userinput; } } else if (userinput == 1) { if (morelikely <= 5) { cout << darknesssceneA; cin >> userinput; } else cout << darknesssceneB; cin >> userinput; } } if (funmeter == 15) { // first choice -- easiest difficulty if (userinput == 0) { if (morelikely >= 3) { cout << creaturesceneA; cin >> userinput; } else { cout << creaturesceneB; cin >> userinput; } } else if (userinput == 1) { if (morelikely >= 3) { cout << darknesssceneA; cin >> userinput; } else cout << darknesssceneB; cin >> userinput; } } cout << "\n\n\t\t\t either way man. you make it out and survive another day\n\n"; return 0; }