title: Program not producing correct value - C++
body: <p>I've been trying to make a GPA calculator as practice. The program compiles but when it couts the avg, it returns a value such as -5.16205e+300. However, after calculating the avg in each for loop, if I put cout &lt;&lt; avg; it returns the correct value in the end. I would appreciate any help, thank you!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main(){
      {
          string ordinal, l_grade;
          int units;
          double num, sum, avg;
  
          cout &lt;&lt; "How many units (maximum of 5)?: ";
          cin &gt;&gt; units;
  
          switch(units){
          case 0:
          {
              cout &lt;&lt; "Can't calculate GPA with 0 units.";
          } break;
  
          case 1:
          {
              for(int i = 1; i &lt;= units; i++){
                  {
                      switch(i){
                          case 1:
                          ordinal = "first";
                          break;
                      }
                      cout &lt;&lt; "Enter your " &lt;&lt; ordinal &lt;&lt; " letter grade: ";
                      cin &gt;&gt; l_grade;
  
                      if (l_grade == "A" || l_grade == "a"){
                          num = 4.00;
                      } else if(l_grade == "A-" || l_grade == "a-"){
                          num = 3.67;
                      } else if(l_grade == "B+" || l_grade == "b+"){
                          num = 3.33;
                      } else if(l_grade == "B" || l_grade == "b"){
                          num = 3.00;
                      } else if(l_grade == "B-" || l_grade == "b-"){
                          num = 2.67;
                      } else if(l_grade == "C+" || l_grade == "c+"){
                          num = 2.33;
                      } else if(l_grade == "C" || l_grade == "c"){
                          num = 2.00;
                      } else if(l_grade == "C-" || l_grade == "c-"){
                          num = 1.67;
                      } else if(l_grade == "D+" || l_grade == "d+"){
                          num = 1.33;
                      } else if(l_grade == "D" || l_grade == "d"){
                          num = 1.00;
                      } else if(l_grade == "F" || l_grade == "f"){
                          num = 0.00;
                      } else cout &lt;&lt; "You entered an invalid letter grade.";
                  }
                  sum += num;
                  avg = sum / units;
              }
              cout &lt;&lt; "Your average is " &lt;&lt; avg;
          } break;
  
          case 2:
          {
              for(int i = 1; i &lt;= units; i++){
                  {
                      switch(i){
                          case 1:
                          ordinal = "first";
                          break;
  
                          case 2:
                          ordinal = "second";
                          break;
                      }
                      cout &lt;&lt; "Enter your " &lt;&lt; ordinal &lt;&lt; " letter grade: ";
                      cin &gt;&gt; l_grade;
  
                      if (l_grade == "A" || l_grade == "a"){
                          num = 4.00;
                      } else if(l_grade == "A-" || l_grade == "a-"){
                          num = 3.67;
                      } else if(l_grade == "B+" || l_grade == "b+"){
                          num = 3.33;
                      } else if(l_grade == "B" || l_grade == "b"){
                          num = 3.00;
                      } else if(l_grade == "B-" || l_grade == "b-"){
                          num = 2.67;
                      } else if(l_grade == "C+" || l_grade == "c+"){
                          num = 2.33;
                      } else if(l_grade == "C" || l_grade == "c"){
                          num = 2.00;
                      } else if(l_grade == "C-" || l_grade == "c-"){
                          num = 1.67;
                      } else if(l_grade == "D+" || l_grade == "d+"){
                          num = 1.33;
                      } else if(l_grade == "D" || l_grade == "d"){
                          num = 1.00;
                      } else if(l_grade == "F" || l_grade == "f"){
                          num = 0.00;
                      } else cout &lt;&lt; "You entered an invalid letter grade.";
  
                  }
                  sum += num;
                  avg = sum / units;
              }
              cout &lt;&lt; "Your average is " &lt;&lt; avg;
          } break;
  
          case 3:
          {
              for(int i = 1; i &lt;= units; i++){
                  {
                      switch(i){
                          case 1:
                          ordinal = "first";
                          break;
  
                          case 2:
                          ordinal = "second";
                          break;
  
                          case 3:
                          ordinal = "third";
                          break;
                      }
                      cout &lt;&lt; "Enter your " &lt;&lt; ordinal &lt;&lt; " letter grade: ";
                      cin &gt;&gt; l_grade;
  
                      if (l_grade == "A" || l_grade == "a"){
                          num = 4.00;
                      } else if(l_grade == "A-" || l_grade == "a-"){
                          num = 3.67;
                      } else if(l_grade == "B+" || l_grade == "b+"){
                          num = 3.33;
                      } else if(l_grade == "B" || l_grade == "b"){
                          num = 3.00;
                      } else if(l_grade == "B-" || l_grade == "b-"){
                          num = 2.67;
                      } else if(l_grade == "C+" || l_grade == "c+"){
                          num = 2.33;
                      } else if(l_grade == "C" || l_grade == "c"){
                          num = 2.00;
                      } else if(l_grade == "C-" || l_grade == "c-"){
                          num = 1.67;
                      } else if(l_grade == "D+" || l_grade == "d+"){
                          num = 1.33;
                      } else if(l_grade == "D" || l_grade == "d"){
                          num = 1.00;
                      } else if(l_grade == "F" || l_grade == "f"){
                          num = 0.00;
                      } else cout &lt;&lt; "You entered an invalid letter grade.";
                  }
                  sum += num;
                  avg = sum / units;
              }
              cout &lt;&lt; "Your average is " &lt;&lt; avg;
          } break;
  
          case 4:
          {
              for(int i = 1; i &lt;= units; i++){
                  {
                      switch(i){
                          case 1:
                          ordinal = "first";
                          break;
  
                          case 2:
                          ordinal = "second";
                          break;
  
                          case 3:
                          ordinal = "third";
                          break;
  
                          case 4:
                          ordinal = "fourth";
                          break;
                      }
                      cout &lt;&lt; "Enter your " &lt;&lt; ordinal &lt;&lt; " letter grade: ";
                      cin &gt;&gt; l_grade;
  
                      if (l_grade == "A" || l_grade == "a"){
                          num = 4.00;
                      } else if(l_grade == "A-" || l_grade == "a-"){
                          num = 3.67;
                      } else if(l_grade == "B+" || l_grade == "b+"){
                          num = 3.33;
                      } else if(l_grade == "B" || l_grade == "b"){
                          num = 3.00;
                      } else if(l_grade == "B-" || l_grade == "b-"){
                          num = 2.67;
                      } else if(l_grade == "C+" || l_grade == "c+"){
                          num = 2.33;
                      } else if(l_grade == "C" || l_grade == "c"){
                          num = 2.00;
                      } else if(l_grade == "C-" || l_grade == "c-"){
                          num = 1.67;
                      } else if(l_grade == "D+" || l_grade == "d+"){
                          num = 1.33;
                      } else if(l_grade == "D" || l_grade == "d"){
                          num = 1.00;
                      } else if(l_grade == "F" || l_grade == "f"){
                          num = 0.00;
                      } else cout &lt;&lt; "You entered an invalid letter grade.";
                  }
                  sum += num;
                  avg = sum / units;
              }
              cout &lt;&lt; "Your average is " &lt;&lt; avg;
          } break;
  
          case 5:
          {
              for(int i = 1; i &lt;= units; i++){
                  {
                      switch(i){
                          case 1:
                          ordinal = "first";
                          break;
  
                          case 2:
                          ordinal = "second";
                          break;
  
                          case 3:
                          ordinal = "third";
                          break;
  
                          case 4:
                          ordinal = "fourth";
                          break;
  
                          case 5:
                          ordinal = "fifth";
                          break;
                      }
                      cout &lt;&lt; "Enter your " &lt;&lt; ordinal &lt;&lt; " letter grade: ";
                      cin &gt;&gt; l_grade;
  
                      if (l_grade == "A" || l_grade == "a"){
                          num = 4.00;
                      } else if(l_grade == "A-" || l_grade == "a-"){
                          num = 3.67;
                      } else if(l_grade == "B+" || l_grade == "b+"){
                          num = 3.33;
                      } else if(l_grade == "B" || l_grade == "b"){
                          num = 3.00;
                      } else if(l_grade == "B-" || l_grade == "b-"){
                          num = 2.67;
                      } else if(l_grade == "C+" || l_grade == "c+"){
                          num = 2.33;
                      } else if(l_grade == "C" || l_grade == "c"){
                          num = 2.00;
                      } else if(l_grade == "C-" || l_grade == "c-"){
                          num = 1.67;
                      } else if(l_grade == "D+" || l_grade == "d+"){
                          num = 1.33;
                      } else if(l_grade == "D" || l_grade == "d"){
                          num = 1.00;
                      } else if(l_grade == "F" || l_grade == "f"){
                          num = 0.00;
                      } else cout &lt;&lt; "You entered an invalid letter grade.";
                  }
                  sum += num;
                  avg = sum / units;
              }
              cout &lt;&lt; "Your average is " &lt;&lt; avg;
          } break;
  
          default:
          {
              cout &lt; "You entered an invalid number.";
          } break;
      }
  }
  return  0;
  </code></pre>
  
  <p>}</p>