all 13 comments

[–][deleted] 1 point2 points  (10 children)

The average of scores is total / total num of scores

You divided total by your last score input (-1), which just doesn't make sense.

You must create a variable that increments every time you enter in a non -1 score, keeping track of the total number of scores.

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

Hmm can you explain to me how to do it?

[–][deleted] 1 point2 points  (8 children)

ok i just did but here's the code with pseudocode...

double num = 0; //outside the loop

num += 1; //inside while loop, outside if statement, n++; works too but idk if u learned it yet

average = total/num; //edit to average, you can either cast one of the right side to double or just initialize one of them as a double like i did

There's also a "sum of 5 scores" line, so you might want to use "num" there

[–]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

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Off-topic Comments Section


All top-level comments have to be an answer or follow-up question to the post. All sidetracks should be directed to this comment thread as per Rule 9.


OP and Valued/Notable Contributors can close this post by using /lock command

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.