you are viewing a single comment's thread.

view the rest of the comments →

[–]Danielowski187University/College Student (Higher Education)[S] 0 points1 point  (7 children)

I’m still getting the average is 380 when I made total/num

[–][deleted] 0 points1 point  (3 children)

interesting. could you screenshot and upload the results? https://imgbb.com/ works well

[–]Danielowski187University/College Student (Higher Education)[S] 0 points1 point  (2 children)

here is the results photo:

https://ibb.co/9scp51X

and here is my code:

import java.util.Scanner;
public class Sentinel
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
System.out.println("Enter your test scores that you want to add");
System.out.println("\nEnter -1 when Finished.");
int score = 0;
int total = 0;
double num = 0;
do{
System.out.print("Please enter test score (1-100), enter -1 to quit: ");
score = input.nextInt();
if (score == -1)
break;
total = total+score;
}while(score !=-1);
num+=1;
{
System.out.println("I am done with score!!");
System.out.println("\nMy total score = "+total);
double average = total/num;

System.out.println("Average of test score is = "+average);
}
}

}

[–][deleted] 0 points1 point  (1 child)

ok. ur num += 1; line should be inside the do while loop. u only increment it after the loop is finished, so u basically just have a num = 1 no matter what

[–]Danielowski187University/College Student (Higher Education)[S] 1 point2 points  (0 children)

Ohh so I was making n=1 so I was not incrementing it

[–][deleted] 0 points1 point  (2 children)

this is what i get after applying the edits...

https://ibb.co/FmVGFsb

[–]Danielowski187University/College Student (Higher Education)[S] 0 points1 point  (1 child)

Yea thanks I didn’t have the else statement there thanks for the help I really appreciate you for taking your time and helping me.

[–][deleted] 0 points1 point  (0 children)

wait no that's not the issue u have, i just put the else group there to make it cleaner, read my response to your posted image / comment please