Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me Create a program that allows the user to enter the gender (e

ID: 3921343 • Letter: C

Question

Can someone help me Create a program that allows the user to enter the gender (either F or M) and GPA (0.0 through 4.0) for any number of students. The program should calculate and display the average GPA for all students, the average GPA for male students, and the average GPA for female students. If necessary, create a new project named lntermediate23 Project, and save it in the Cpp8Chap07 folder. Enter the C++ instructions into a source file named Intermediate23.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Save, run, and test the program.

Explanation / Answer

#include <iostream>
using namespace std;
int main(void)
{
   char ch;
   float gpa,mgpa,fgpa;
   int m,f;
   m=0;f=0;mgpa=0;fgpa=0;
   cout<<"Enter gender and gpa(q to quit):";
   while(true)
   {
       cin>>ch;
       if(ch=='q')
       {
           break;
       }
       cin>>gpa;
       if(ch=='M')
       {
           m++;
           mgpa+=gpa;
       }
       else if(ch=='F')
       {
           f++;
           fgpa+=gpa;
       }
       else
       {
           cout<<"unknown input"<<endl;
       }
       cout<<"Enter gender and gpa(q to quit):";
   }
   if(m>0)
   {
       cout<<"The average gpa for male students is "<<mgpa/m<<endl;
   }
   else
   {
       cout<<"There are no male students"<<endl;
   }
   if(f>0)
   {
       cout<<"The average gpa for female students is "<<fgpa/f<<endl;
   }
   else
   {
       cout<<"There are no female students"<<endl;
   }


   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote