title: How to use and make a GLOBAL variable to use in different functions?
body: <p>I know I need to avoid global variables as much as possible but somehow I need to use certain variables in other functions. 
  This program is a recipe program. Adds, deletes and views recipes. Everything is working. Maybe not the best code but it works. The second part of the task is to make it so that:
  THE USER INPUTS THE AMOUNT OF PEOPLE HE NEEDS TO SERVE WITH THE RECIPE. THE PROGRAM MUST CHANGE THE RECIPE QUANTITIES TO SUIT HIS NEEDS.</p>
  
  <p>My plan was to make a variable called "multiplier" which is multiplied by each quantity however I don't know whether there is a better way. Unfortunately since the variables I need are in "addRecipe" I cannot possibly access them. I require "int people" and "int quan[]" so I can divide the Number of servings he wants by the number of people the recipe is for. This will give me a multiplier which I then use to multiply each NUMERICAL value within the array. The array is then outputted differently without changing the recipe.
  This may not be the best plan and I have attempted it several times using parameters but I cannot seem to make it work. The code is below as is my attempts. </p>
  
  <pre><code>// Recipe.cpp : Defines the entry point for the console application.
  //
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      return 0;
  }
  // Practice.cpp : Defines the entry point for the console application.
  //
  
  // 2a
  #include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;dirent.h&gt;
  using namespace std;
  
  
  void deleteRecipe(){
      DIR *dp;
         struct dirent *ep;
  
         dp = opendir ("C:\\Users\\The\\Documents\\Visual Studio 2010\\Projects\\Recipe\\Recipe");
         if (dp != NULL)
           {
             while (ep = readdir (dp))
               puts (ep-&gt;d_name);
             (void) closedir (dp);
           }
         else
           perror ("Couldn't open the directory");
  cout&lt;&lt; "Please input the file you would like to delete from the list above: "&lt;&lt;endl;
  string dName;
  cin&gt;&gt;dName;
  remove(dName.c_str());
  cout&lt;&lt;"The recipe has BEEN DELETED! " &lt;&lt;endl;
  
  system("pause");
  
  }
  
  int addRecipe(){
      //PART B OF PROBLEM!
      int count = 1;
      string title;
      string item;
      int quan [100];
      string units;
      int people;
      cout&lt;&lt;"What is the title of your new recipe?"&lt;&lt;endl;
      cin.ignore();
      getline(cin, title);
      ofstream outFile(title+".txt", ios::out);
      cout&lt;&lt; "How many people will this recipe serve?"&lt;&lt;endl;
      cin&gt;&gt;people;
      cout&lt;&lt; title &lt;&lt; " - Servings: " &lt;&lt; people &lt;&lt; " people" &lt;&lt;endl;
      cout&lt;&lt;" Please type your ingredients in the format as follows. Be to sure to input a '#'upon completion."&lt;&lt;endl;
      while (count&lt;1000){
          cout&lt;&lt; "Enter Item: "&lt;&lt;endl;
          cin.ignore();
          getline(cin, item,'#');
          cout&lt;&lt; "Enter Quantity: "&lt;&lt;endl;
          cin&gt;&gt;quan[];
          cout&lt;&lt; ("Enter units")&lt;&lt;endl;
          getline(cin, units);
      count = count++;
      }
      cout&lt;&lt; "Thank you for inputting your recipe. To view your recipe, please do nothing."&lt;&lt;endl;
      outFile &lt;&lt; title &lt;&lt;endl;
      outFile&lt;&lt; people &lt;&lt; " People" &lt;&lt;endl;
      outFile&lt;&lt; item&lt;&lt;endl;
  return 0;
  }
  int viewRecipe(){
       DIR *dp;
         struct dirent *ep;
  
         dp = opendir ("C:\\Users\\The\\Documents\\Visual Studio 2010\\Projects\\Recipe\\Recipe");
         if (dp != NULL)
           {
             while (ep = readdir (dp))
               puts (ep-&gt;d_name);
             (void) closedir (dp);
           }
         else
           perror ("Couldn't open the directory");
         cout&lt;&lt;"Please type in the name file you want to view from the list above: "&lt;&lt;endl;
  
  
         string fileName;
         string line;
         cin&gt;&gt; fileName;
         ifstream inData;
         inData.open(fileName.c_str());
         if (inData.is_open())
    {
      while ( getline (inData,line) )
      {
        cout &lt;&lt; line &lt;&lt; '\n';
      }
      inData.close();
      int multiplier = 0;
      char choice;
      int newAmount;
      cout&lt;&lt;"That was the original. If you would like to view the same recipe with a different amount of servings please press '#'."&lt;&lt;endl;
      // PART A OF PROBLEM!
      if (choice= '#'){
          cout&lt;&lt;"How many servings would you like to adapt the recipe to?"&lt;&lt;endl;
          cin&gt;&gt;newAmount;
          multiplier = newAmount/ addRecipe(0, );
  
      }
  
         }
  return 0;
  }
  
  
  int menu(){
       int input = 0;
       cout&lt;&lt; "1: View Recipe" &lt;&lt;endl;
       cout&lt;&lt; "2: Add Recipe" &lt;&lt;endl;
       cout&lt;&lt; "3: Delete Recipe" &lt;&lt;endl;
       cout&lt;&lt; "Please select an option"&lt;&lt;endl;
       cin&gt;&gt;input;
       if (input == 1){
           viewRecipe();}
       if (input == 2){
           addRecipe();}
       if (input == 3){
           deleteRecipe();}
  
  
      return 0;
  }
  
  
  int main(){
      menu();
  
  
  system("pause");
  cin.get();
  return 0;
  }
  </code></pre>
  
  <p>My attempt which does not work:</p>
  
  <pre><code>int addRecipe(int people, int quan[]){
      int count = 1;
      string title;
      string item;
      int quan [100];
      string units;
      int people;
      cout&lt;&lt;"What is the title of your new recipe?"&lt;&lt;endl;
      cin.ignore();
      getline(cin, title);
      ofstream outFile(title+".txt", ios::out);
      cout&lt;&lt; "How many people will this recipe serve?"&lt;&lt;endl;
      cin&gt;&gt;people;
      cout&lt;&lt; title &lt;&lt; " - Servings: " &lt;&lt; people &lt;&lt; " people" &lt;&lt;endl;
      cout&lt;&lt;" Please type your ingredients in the format as follows. Be to sure to input a '#'upon completion."&lt;&lt;endl;
      while (count&lt;1000){
          cout&lt;&lt; "Enter Item: "&lt;&lt;endl;
          cin.ignore();
          getline(cin, item,'#');
          cout&lt;&lt; "Enter Quantity: "&lt;&lt;endl;
          cin&gt;&gt;quan[];
          cout&lt;&lt; ("Enter units")&lt;&lt;endl;
          getline(cin, units);
      count = count++;
      }
      cout&lt;&lt; "Thank you for inputting your recipe. To view your recipe, please do nothing."&lt;&lt;endl;
      outFile &lt;&lt; title &lt;&lt;endl;
      outFile&lt;&lt; people &lt;&lt; " People" &lt;&lt;endl;
      outFile&lt;&lt; item&lt;&lt;endl;
  return 0;
  }
  int viewRecipe(int multiplier){
       DIR *dp;
         struct dirent *ep;
  
         dp = opendir ("C:\\Users\\The\\Documents\\Visual Studio 2010\\Projects\\Recipe\\Recipe");
         if (dp != NULL)
           {
             while (ep = readdir (dp))
               puts (ep-&gt;d_name);
             (void) closedir (dp);
           }
         else
           perror ("Couldn't open the directory");
         cout&lt;&lt;"Please type in the name file you want to view from the list above: "&lt;&lt;endl;
  
  
         string fileName;
         string line;
         cin&gt;&gt; fileName;
         ifstream inData;
         inData.open(fileName.c_str());
         if (inData.is_open())
    {
      while ( getline (inData,line) )
      {
        cout &lt;&lt; line &lt;&lt; '\n';
      }
      inData.close();
      int multiplier = 0;
      char choice;
      int newAmount;
      int x = addRecipe(people, void)
      cout&lt;&lt;"That was the original. If you would like to view the same recipe with a different amount of servings please press '#'."&lt;&lt;endl;
      if (choice= '#'){
          cout&lt;&lt;"How many servings would you like to adapt the recipe to?"&lt;&lt;endl;
          cin&gt;&gt;newAmount;
          multiplier = newAmount/ addRecipe(, );
  
      }
  </code></pre>