I am just trying out some basic c++ stuff and i was hoping someone could tell me some better ways to put my code together. I know its messy but if anyone could help make it cleaner and faster, and any other bits of advice on it so far, i would greatly appreciate it. This is for nothing in particular at the moment, just some practice.
Thanks
werdy666
Code:#include <iostream> #include <windows.h> // for Sleep(Dword) #include <time.h> #include <string> using namespace std; // Global Variables int input = NULL; int selection = NULL; bool quitgame = false; bool choice = false; // functions.......... int main_menu(); int create_new_player(); int load_char(); int main_menu_choose(); // Main..... int main() { srand( (unsigned) time(NULL)); while(quitgame == false) { if (main_menu() != 1) { cout << "error in main menu code. Quiting!"; exit(1); } // ending if (main_menu() != 1) selection = main_menu_choose(); if (selection == 0) { cout << "error in function choose!" << endl; exit(1); } switch(selection) { case 1: cout << "You have chosen and finished creating a new character!" << endl; break; case 2: cout << "You have successfully loaded a character from disk!" << endl; break; } // end switch(selection) } // end while( quitgame == false); }//end main(); int main_menu() { cout << " ----------------------------------------------- " << endl; cout << " Please choose an option :" << endl << endl ; cout << " 1. Create New Character " << endl; cout << " 2. Load a Saved Character " << endl; cout << " 3. Quit game " << endl; return 1; } int create_new_player() { char answer = NULL; int counter = 0; int str=0,intel=0,dex=0,hp=0; cout << "create new player/character function. You can only reroll stats 3 times!" << endl; while (counter < 4) { counter++; str = rand()%14+4; intel = rand()%14+4; dex = rand()%14+4 ; hp = rand()%10+4+(str/3); cout << " Strength : " << str << endl; cout << " Intelligence : " << intel << endl; cout << " Dexterity : " << dex << endl; cout << " Hitpoints " << hp << endl; if (counter < 4) { cout << endl << "Do you wish to keep these stats?(Y/N) " ; cin >> answer ; if ((answer == 'y') || (answer == 'Y')) break; } }// end while counter < 4 string name = ""; cout << endl << endl << "What is your new character's name??" << endl; cin >> name; cout << endl << endl; cout << name << endl; cout << "Strength : " << str << endl; cout << "Intelligence : " << intel << endl; cout << "Dexterity : " << dex << endl; cout << "Hitpoints : " << hp << endl; cout << endl << "Do you wish to save this character? " << endl; Sleep(2000); return 1; } int load_char() { cout << "load char function" << endl; Sleep(2000); return 1; } int main_menu_choose() { while(choice == false) { cin >> input ; switch(input) { case 1: // Make a new character has been chosen! create_new_player(); quitgame = false; return 1; break; case 2: // Load a saved character load_char(); quitgame = false; return 2; break; case 3: quitgame = true; return 3; break; default: cout << "Please Choose 1,2 or 3." << endl; choice = false; break; } // end switch(input); }// end while return 0; }



LinkBack URL
About LinkBacks


