How to get the sum of numbers in a while loop

package Week6;

//class JOption for dialogue box input and output import javax.swing.JOptionPane; public class week6 { public static void main(String[] args) {

String gender="",major="",GPAinput="",creditsin=""; String more= "yes"; double GPA= 0; double cispercent=0,mathpercent=0; //SET A VARIABLE TO A REALLY LOW VALUE THEN COMPARE IT IN THE LOOP AS A NEW GPA IS READ IN double high_cis_gpa=0,high_math_gpa=0,GPAAVG=0; int credits,cisstudent=0,mathstudent=0,femalecis=0,malemath=0,senior=0,freshman=0,total_survey=0; while(more.equals("yes")) { //Input Section gender = JOptionPane.showInputDialog(null,"Is the student male or female?","Input", JOptionPane.QUESTION_MESSAGE); major = JOptionPane.showInputDialog(null,"What is the students major? CIS or Math","Input", JOptionPane.QUESTION_MESSAGE); GPAinput= JOptionPane.showInputDialog(null,"What is the students GPA?", JOptionPane.QUESTION_MESSAGE); GPA = Double.parseDouble(GPAinput); creditsin= JOptionPane.showInputDialog(null,"How many credits does the student have?","Input", JOptionPane.QUESTION_MESSAGE); credits = Integer.parseInt(creditsin); if (major.equals("cis")) { cisstudent++; if (GPA>high_cis_gpa) high_cis_gpa=GPA; } else { mathstudent++; if (GPA>high_math_gpa) high_math_gpa=GPA; }

    if (gender.equals("male") && major.equals("math"))
        {
        malemath++;
        }

    if (gender.equals("female") && major.equals("cis"))
        {
        femalecis++;
        }
    if (credits <= 36)
        {
        freshman++;
        }
    if (credits >=96)
        {
        senior++;
        }
total_survey++; 
more = JOptionPane.showInputDialog(null,"More Data? yes or no","Input", JOptionPane.QUESTION_MESSAGE);
}

//calculation section
cispercent=cisstudent*1.0/total_survey;
mathpercent=mathstudent*1.0/total_survey;

// Print Section
System.out.println("Total number of people: " +total_survey);
System.out.println("Total number of Math students: "+mathstudent); 
System.out.println("The percent of Math Students: "+mathpercent); 
System.out.println("Total number of CIS students: " +cisstudent);
System.out.println("The percent of CIS students: "+cispercent); 
System.out.println("Total number of females who majored in CIS: "+femalecis); 
System.out.println("Total number of males who majored in Math: "+malemath); 
System.out.println("Total number of people who are seniors: "+senior); 
System.out.println("Total number of people who are freshman: "+freshman); 
System.out.println("The average GPA for both majors is "+GPAAVG);
System.out.println("The highest CIS GPA is "+high_cis_gpa);
System.out.println("The highest Math GPA is "+high_math_gpa);
System.exit(0);
}

I know that GPAAVG will have to be =GPATotal/total_survey; but I dont know how to get the whole total of all of them that are randomly inputted.

/r/javahelp Thread Parent