CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Thumbs down Stack around the variable 'dive_scores' was corrupted.

    Hey everyone I'm having some trouble with my C++ program to calculate the average of 7 dive scores and I am getting the error "Stack around the variable 'dive_scores' was corrupted. Thanks

    Code:
    int main()
    {
       double dive_scores[6]; // an array of 7 elements
       double single_dive_score; // the input of each dive score
       double diff_factor = 0.0; // the input of the difficulty factor
       double sum = 0.0; // sum of the dive scores
       double avg = 0.0; // average of the scores
    
       int n = 0;    // the number of items read from the user
    
       
       // initialize!
       for (int i = 0; i < 7; i++)
       {
          dive_scores[i] = 0.0;
       }
    
       
    
       // perform input
       while ( n < 7 )
       {
           // prompt the user and read the value...
    	   cout << "Enter score " << (n+1) << " between 0.0 and 10.0 " << endl;
    	   cin >> single_dive_score;
    
    	   if (single_dive_score <= 10)
    	   {
    		   dive_scores[n] = single_dive_score;
    		   n++;
    	   }
    	   else if ((single_dive_score < 0) || (single_dive_score > 10))
    	   {
    	      cout << "Invalid Number" << endl;
    
    		  return 0;
    	   }
    
       }
    
       if (n > 0) 
       { 
          //calculate the average...
          for(int i = 0; i < n; i++)
    	  {
    	     sum+= dive_scores[i];
    	  }
    	  // do the final step in the average calculation...
    	  avg = computeAverage(sum,n);
       }
    
       cout << "Enter difficulty factor:" << endl;
       cin >> diff_factor;
    
       for (n = 0; n < 7; n++)
       {
    	   std::cout << "Dive Score #" << (n+1) << ":" << dive_scores[n] << std::endl;
       }
       //calcuate the final score...
       outputFinal(avg,diff_factor);
    
    
    
    
    
       // exit the program with success (0 == success)
       return 0;
    	
    }
    
    
    double computeAverage(double sum, int n)
    {
       double avg = 0.0;
    
       //compute the average of the scores
       avg = sum / n;
    
       return avg;
    }
    
    
    double outputFinal(double avg, double diff_factor)
    {
       double final_score = 0.0;
    
       final_score = (avg * diff_factor);
    
       return final_score;
    }
    Last edited by thesaintex2; April 5th, 2009 at 08:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured