Programming using C Also include comments in each step to ex
Programming using C++
Also include comments in each step to explain what it does in the program. The program should display similarly to Figure 1 and Figure 2.
Solution
#include <iostream>
 #include <stdlib.h>
 using namespace std;
int main()
 {
    int i,n,countmore50,countless50;
    float average,highest,lowest;
   
    average = 0;
    countmore50 = 0;
    countless50 = 0;
   
    highest =0;
    lowest =100;
   
    cout<<\"\ \\t\\t\\tNancy\'s Statistics Generator\";
    cout<<\"\ \\t\\t\\t-----------------------------\";
   
    cout<<\"\ Hello Professor, how many grades do I need to analyse this time>\";
    cin>>n;
   
    if(n == 0)
    {
    cout<<\"\ \ Guess you changed your mind\";
    cout<<\"\  Ending the program now\";
    exit(0);
    }
   
    float grades[n];
   
    cout<<\"\ \ Okay, I am ready. Start..... \";
    for(i=0;i<n;i++)
    cin>>grades[i];
   
    cout<<\"\ Here are the requested stats for the \"<<n<<\" grades\";
    for(i=0;i<n;i++) //input grades
    {
        average = average + grades[i];
       
        if(highest<grades[i])   
        highest = grades[i];
       
        if(lowest > grades[i])
        lowest = grades[i];
       
        if(grades[i]<50)
        countless50++;
       
        if(grades[i]>=50)
        countmore50++;
       
       
       
       
    }
    //display stats
    cout<<\"\ The class average is \"<<average/n;
    cout<<\"\ The highest grade is \"<<highest;
    cout<<\"\ The lowest grade is \"<<lowest;
    cout<<\"\ The number of students who scored less than 50 is \"<<countless50;
    cout<<\"\ The number of students who scored 50 or better is \"<<countmore50;
   
    cout<<\"\ \ Thats it!!!\";
   
    return 0;
 }
output:


