i need to create a program that allows a user to enter gende

i need to create a program that allows a user to enter gender and GPA (0.0 to 4.0) for any number of students then it should calcualte the average and display that total in three ways. for all students then male student and last female students. I asked this before but needed it in C++

Solution

We are computing the average at current iteration and using this average value to calculate it for the next time for male & female. We can use individual male & female average value to compute final average value

#include <iostream>
using namespace std;

int main() {
   float mavg=0,favg=0;
   int male=0,female=0;
   char c;
   do
   {
       char ch;
       float gpa;
       cin>>ch>>gpa;
       if(ch==\'M\')
       {
           mavg=((mavg*male)+gpa)/(male+1);
           male++;
       }
       else
       if(ch==\'F\')
       {
           favg=((favg*female)+gpa)/(female+1);
           male++;
       }
       float avg=((favg*female)+(mavg*male))/(male+female);
       cout<<\"Average : \"<<avg<<\"\ Male average : \"<<mavg<<\"\ Female average : \"<<favg;
       cout<<\"\ Wish to continue,Enter Y : \";
       cin>>c;
   }
   while(c==\'Y\' || c==\'y\');
  
   return 0;
}

i need to create a program that allows a user to enter gender and GPA (0.0 to 4.0) for any number of students then it should calcualte the average and display t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site