I am having a hard time with a homework problem getting my program to output a percentage properly. My goal is to just have my percentages be two decimal places out, even if it is 0.00%. Keep in mind, this is a level one programming course so the solution should be fairly basic, I just don't know why I can't see it. Thank you for your help.
I get these outputs:
supposed to be > 7 evens (100.00%) mine > 7 evens (100.0%)
supposed to be > 4 evens (36.36%) mine > 4 evens (36.36363636363637%)
Below is my code:
while(input.hasNextInt()) {
int num = input.nextInt();
totalcount++;
totalsum = totalsum + num;
if(num % 2 == 0) {
totaleven++;
}
}
double percent = (((double)totaleven/totalcount) * 100.00); <<< this right here
System.out.println(totalcount + " numbers, sum = " + totalsum);
System.out.println(totaleven + " evens " + "("+percent+"%)");
}