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

Greetings, I\'m just looking for a bit of help here. Here\'s the prompt: For res

ID: 3619945 • Letter: G

Question

Greetings,

I'm just looking for a bit of help here. Here's the prompt:

For research purposes the admissions officers of your local university wants to know how well female and male students perform in certain courses. The user enters the number of courses to be considered. The student's data for each course is provided as a GPA followed by a letter code representing the gender of the student in this format: each line of input consists of a real number representing the student's GPA followed by the letter code f (for female students); m (for male students).
The number of entries (students) for each course is not known and the number 0.0 followed by the letter O indicates the end of data for specific course.

That being said, this is an introduction to c++ and as such; arrays, strings, and anything else outside of int, floats, doubles, and char is basically not allowed. In the code there needs to be the ability to type in various entries in any order (male entry followed by female and as well as the opposite.) the issue i'm having is this: I can input values (nonzero values) beginning with female entries and sum is fine, but when I input values beginning with male first, the sum for female is math jargon. Any help in solving this small issue would be greatly appreciated. Thanks

here is my code:

//GPA calculator for Ghemri
//dealing with gpa range 0.0-4.0, set cap?

#include

using namespace std;

int main(void)
{
int size, counter;
//int studentTotal= 0;
char gender;
double studentInfo,total,sum, avg;
double minGpa = 0.0, maxGpa = 4.0;
double femaleSum, femaleAvg, femaleTotal;
double maleSum, maleAvg, maleTotal;
int femaleNumber,maleNumber;


cout << " Please enter the number of courses you want considered: ";

cin >> size;

while(size <=0)
{
cout << " Invalid entry, number of course must be greater than zero ";

cin >> size;
}

for(int course =1; course <= size; course++)
{
maleTotal = 0;
femaleTotal=0;
total = 0;
femaleNumber = 0;
maleNumber = 0;

cout << " Enter student information(0.0 O to end): ";

cin >> studentInfo >> gender;

while(studentInfo < minGpa || studentInfo > maxGpa)
{
cout << " Invalid entry, try again... ";

cout << "Enter student's information(0.0 O to end): ";

cin >> studentInfo >> gender;
}

if(gender == 'f' || gender == 'F' && studentInfo > minGpa && studentInfo < maxGpa)
{
femaleNumber=1;
femaleSum = studentInfo;
}
if(gender == 'm' || gender == 'M' && studentInfo > minGpa && studentInfo < maxGpa)
{
maleNumber=1;
maleSum = studentInfo;
}

sum =studentInfo;
counter = 0;
counter++;


while(studentInfo != 0.0 && gender != 'O')
{

cout << "Enter student information(0.0 O to end): ";

cin >> studentInfo >> gender;

if(studentInfo < minGpa || studentInfo > maxGpa)
{
cout << " Invalid entry, try again... ";

cout << "Enter student's information(0.0 O to end): ";

cin >> studentInfo >> gender;
}

if(gender != 'm' && gender !='f' && gender != 'O')
{
cout << "Invalid entry, enter m for male or f for female ";

cout << "Enter student's information(0.0 O to end): ";

cin >> studentInfo >> gender;
}
sum +=studentInfo;
total+=counter;
avg = sum/total;

if(gender == 'f' || gender =='F')
{
femaleSum+=studentInfo;
femaleNumber++;
//femaleTotal+=femaleNumber;
femaleAvg = femaleSum/femaleNumber;

}

if(gender == 'm' || gender == 'M')
{
maleSum+=studentInfo;
maleNumber++;
//maleTotal+=maleNumber;
maleAvg = maleSum/maleNumber;
}

if(studentInfo == 0 && gender == 'O')
{
cout << " Number of females is: " << femaleNumber << endl;
//cout << " sum of female is: " << femaleSum << endl;
cout << " the number of males is: " << maleNumber << endl;
cout << " Results for course "<< course<<": ";
cout << "Female Student Average Male Student Average ";
cout << " " << femaleSum << " " << maleSum << endl;
cout << "avg " << avg << endl;
}
}
}

return 0;
}



That being said, this is an introduction to c++ and as such; arrays, strings, and anything else outside of int, floats, doubles, and char is basically not allowed. In the code there needs to be the ability to type in various entries in any order (male entry followed by female and as well as the opposite.) the issue i'm having is this: I can input values (nonzero values) beginning with female entries and sum is fine, but when I input values beginning with male first, the sum for female is math jargon. Any help in solving this small issue would be greatly appreciated. Thanks

Explanation / Answer

please rate - thanks your biggest problem was you were confusing maleTotal and maleSum. you only needed one. I also cleaned it up - hope you don't mind