title: Switch Statement - Nested Functions - C++
body: <p>I want to have a function called "userPrompt" andit ask for the user to enter a value for integer named "choose" so after that I would be able to use switch statement.</p>
  
  <p>But It dosen't work it says: "choose" undeclared.</p>
  
  <p>I suppose it would start the main function first,and inside of it the first command would be initializing the userPrompt func. then thanks to userPrompt I would have a choose value so that the switch would work.</p>
  
  <p>So what is the problem with this code?</p>
  
  <p>How can I use nested functions?(I hope it is called like that)</p>
  
  <p>Is my code's order wrong?</p>
  
  <p>Any help will be appreciated.</p>
  
  <pre><code>userPrompt(){
  
      int choose;
  
      cout &lt;&lt; " Please Choose An Option : " &lt;&lt; endl;
      cout &lt;&lt; " Type 1 to Add new grades : " &lt;&lt; endl;
      cout &lt;&lt; " Type 2 to Calculate the average grades : " &lt;&lt; endl;
      cout &lt;&lt; " Type 3 to Calculate the total grades : " &lt;&lt; endl;
      cout &lt;&lt; " Type 4 to Exit : " &lt;&lt; endl;    
  
      cin &gt;&gt; choose;
  
  }
  
      int main()
      {
  
          userPrompt();
  
          switch(choose){
  
          case 1
              getGrade();
              userPrompt();
              break;
  
          case 2
  
              int average;
              getGrade();   
  
              average = total/counter;
  
              cout &lt;&lt; average; 
  
              break;     
  
          case 3
  
              getGrade();
              cout &lt;&lt; total;
              break;
  
          case 4
  
              cout &lt;&lt; "Thanks for Trying" &lt;&lt; endl;
  
              return 0;
  
              system("pause");
  
              break;
  
          default
  
              cout &lt;&lt; "Please Choose A Valid Option ! : " &lt;&lt; endl;
              validOption();
  
          }
      }
  </code></pre>