   calling functions
  ok i need help trying to understand  while i failed my final project. teacher :said i didnt call 2 functions prototypes can anyone explain  what he meant??whats the benefit??how can it simplfy my code cause i'm clueless ?#include <string>#include <iostream>#include <fstream>using namespace std;enum items {HEALTHBOOSTER,REOVERJUICE,RELOADCLIP};enum armor {DIAMONDARMOR,PLASMAARMOR,TITANARMOR};struct Player{int credits;int hp;int laser;int attack;string name;bool isAI;};int main(){Player mainPlayer, bat, cyborg, robeast;//for( int i = 1; i < 4;i++ )//players.isAI = true;mainPlayer.isAI = false;mainPlayer.attack = 4;mainPlayer.credits =10; mainPlayer.hp = 20;mainPlayer.laser = 8;bat.isAI = true;bat.credits = 22;bat.attack = 2; bat.hp = 32;bat.laser = 8;bool menu = true;   //used to control main choice loopchar letter;//stores the choice madestring playerName;char choice;ifstream fin;fin.open("gold.txt");do {//displays instructions for main optionscout << "Welcome to Space Glaidtor Colusieum" << endl;cout << "" << endl;cout << "" << endl;cout << "Please Remember to load your Gold !!! " << endl;cout << "" << endl;cout << "" << endl;cout << "Press 'S' - To Start a New Game"  << endl;cout << "Press 'L' - To Load Your Money  " << endl;cout << "Press 'Q' - To Quit" << endl;//choice cin >> letter;switch (letter){  case 'q':  case 'Q':  {  cout << "See you Again soon !!! " << endl;  letter = false;  return 0;  }    break; default:  //handle inappropriate user input cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; cout << "***** 'Please read options again  & Then re-enter  a valid choice.'*****" << endl; cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; break;int gold;case 'L':case 'l':cout << "Loading your gold" << endl;fin >> gold;cout << " You have " << gold << " Gold coins to spend." << endl;break ;case 'S':case 's':   char answer;do{  cout << " Please Enter Your Fighters Name: " << endl;cin >> playerName;cout << "You have entered " << playerName << ". Is thiscorrect? (y/n)" << flush;cin >> answer;if ( static_cast<int>( playerName.length() ) > 10) {// i was trying to figure ouy y it didnt loop just trying outcout << " You have exceed 10 chracters.  Try Again" << endl;answer = 'n';}else if ((answer == 'Y') && (answer == 'y')){cout << playerName << " Let's Begin "<< flush;cin.clear();cin.ignore(500,'\n');}else if ((answer == 'N') && (answer == 'n')){cout <<  " Please Re-enter. " << endl;}} while ((answer == 'N') || (answer == 'n'));cout << "******************************************* " << endl;cout << "******************************************* " << endl;cout << "******************************************* " << endl;cout << "Welcome  " << "" << playerName << "!!!" <<  endl;cout << "******************************************* " << endl;cout << "******************************************* " << endl;cout << "******************************************* " << endl;cout << "" << endl;cout << "" << endl;cout << " Press letter in [] to make your selections." << endl;cout << "" << endl;cout << " Are you ready to attle ?" << endl;cout << "" << endl;cout << "" << endl;cout << " View items [G]eneral store for sale ? " << endl;cout << "" << endl;cout << "" << endl;cout << " View items in [A]rmory for sale? " << endl; cout << "" << endl;cout << "" << endl;cout << " Make Purchase from [V]ending machine?" << endl;cout << "" << endl;cout << "" << endl;cout << " Did you want to [C]lose your wallet ?" << endl;cout << "" << endl;cout << "" << endl;cout << " Or press [Q] to Quit " << endl ;cin >> choice;switch (choice){  case 'q':  case 'Q':  {  cout << "See you Again soon !!! " << endl;  letter = false;  return 0;  }    break;    default:  //handle inappropriate user input cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; cout << "***** 'Please read options again  & Then re-enter a valid choice.'*****" << endl; cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; cout << " "<< endl; break;case 'v':case 'V':{   int selection;    cout << " Please Choose armor  " << endl;   cout << " press number in [] " << endl;   cout << "*******************" << endl;   cout << " Diamond Armor[1] " << endl;   cout << " Titan   Armor[2] " << endl;   cout << " Plasma  Armor[3] " << endl; cin >> selection;   cout << "You have entered " << selection << "  and just " << endl; if (selection == 1) {    cout << " Bought the Diamond armor !!! " << endl;   cout << " You have " << gold - 1000 << " remaining." << endl;   ofstream gold;   gold.open("remaining_gold.txt");   }   else if (selection == 2)   {   cout << " Bought the Titan  armor !!! " << endl;   cout << " You have " << gold - 2000 << " remaining." << endl;ofstream gold;    gold.open("gold.txt");    }   else if (selection == 3)   {   cout << " You Bought the Plasma armor !!! " << endl;   cout << " You have " << gold - 5000 << " remaining." << endl;ofstream gold;    gold.open("remaining_gold.txt");}   else if (selection > 3)   {   cout << " what do you think your doing ?" << endl;   }}   break;    case 'B':case 'b':{ cout << " Get ready to fight  !!!  " << endl; cout << "" << endl; cout << " sorry  not yet implemented " << endl; cout << "" << endl; break;}case 'G':case 'g': {ifstream item;item.open("items.txt");const int ARRAY_SIZE = 9;string goods[ARRAY_SIZE];cout << "Welcome to the '' General store  !! ''" << endl;cout << "For sale: " << endl;for ( int j = 0 ; j < ARRAY_SIZE ; j += 3 ){item >> goods[j];cout << goods[j] << " ";item >> goods[j + 1];  cout << goods[j + 1] << " for ";item >> goods[j + 2];cout << goods[j + 2] << " coins." << endl;//cout << goods[j + 3] <<"You have" << gold << "To spend. " << endl; }}  break;case 'C':  case 'c':  {  cout << " You have " << gold << " remaining." << endl;  ofstream gold;  gold.open("remaining_gold.txt");  break;  }case 'a':case 'A':ifstream wear;wear.open("wears.txt");const int ARRAY_SIZE = 9;string wearz[ARRAY_SIZE];cout << "Welcome to the ''Armory !!''" << endl;cout << "For sale: " << endl;for ( int i = 0 ; i < ARRAY_SIZE ; i += 3 ){wear >> wearz;cout << wearz << " ";wear >> wearz; cout &lt;&lt; wearz &lt;&lt; <span class="cpp-literal">" for "</span>;wear &gt;&gt; wearz;cout &lt;&lt; wearz &lt;&lt; <span class="cpp-literal">" coins."</span> &lt;&lt; endl;<span class="cpp-comment">//cout &lt;&lt; "You have" &lt;&lt; gold &lt;&lt; "To spend. " &lt;&lt; endl; </span>}cout &lt;&lt; endl;wear.close();<span class="cpp-keyword">break</span>;} }    }<span class="cpp-keyword">while</span>( letter != 'q' &amp;&amp; letter != 'Q' );cout &lt;&lt; <span class="cpp-literal">" See you again soon !!!!"</span> &lt;&lt; endl;<span class="cpp-keyword">return</span> <span class="cpp-number">0</span>;}</pre></div><!–ENDSCRIPT–>  
  Sorry if it sounds rude, but the best person to answer that question is your teacher.What were the specifics of the assignment? Did it ask you to write the program using multiple functions?You seem to have written the whole thing in the main function, so maybe that's the problem?As an example of how you can break your program down into smaller functions, let's take this section of code that gets the players name:...do{  cout << " Please Enter Your Fighters Name: " << endl;...} while ((answer == 'N') || (answer == 'n'));...And we'll replace that whole section with this:playerName = GetPlayerName();//call the function called GetPlayerName, and store the result in my local variable called playerNameThen up the top of the file (after "using namespace std;" but before "int main()") we'll add what's called a function prototype.string GetPlayerName();//this declares that there is a function called GetPlayerName, which returns a string.Then right down the bottom of the file we'll actually implement the GetPlayerName function:string GetPlayerName() //N.B. no semi-colon this time!{char answer;string name;do{  cout << " Please Enter Your Fighters Name: " << endl;cin >> name;cout << "You have entered " << name<< ". Is thiscorrect? (y/n)" << flush;cin >> answer;if ( static_cast<int>( playerName.length() ) > 10) {// i was trying to figure ouy y it didnt loop just trying outcout << " You have exceed 10 chracters.  Try Again" << endl;answer = 'n';}else if ((answer == 'Y') && (answer == 'y')){cout << name << " Let's Begin "<< flush;cin.clear();cin.ignore(500,'\n');}else if ((answer == 'N') && (answer == 'n')){cout <<  " Please Re-enter. " << endl;}} while ((answer == 'N') || (answer == 'n'));return name;}If you repeat this process of breaking off small chunks of code into their own functions, then your main function will become a lot simpler and easy to read ;)   ;  Hodgman has beaten me to the punch I see; but it is worth re-iterating what he said.  You want to organise things logically in your programs.  If you don't learn how to do that straight off the bat, people are not going to want to work with you (or even read your code, to be honest).  It's just a case of using the language constructs appropriately so that if you come back to your code in a year or so, it's not a tangled web that you need to fight to interpret.~Shiny   