Help with Average and Variables Please =)
I wanna add:
system print of the average of all the scores that were entered.
and a system print of the maximum of all the scores that were entered.
Can anyone help me and add that in there? ive been trying for hours, even bought a java book. couldnt figure it out haha. And if they could explain what you did thanks!
Code :
public static void main(String[] args) {
// TODO code application logic here
String fName = null;
int count = 0;
Scanner scan = new Scanner(System.in);
while ( fName != "stop" ) {
System.out.println("Enter the user's score from 0 to 100 ");
System.out.println("....or you can always enter STOP to quit the app.");
System.out.println("So far you have entered only " + count + " grades.");
System.out.print("\nINPUT: ");
int score = scan.nextInt();
count++;
if (score >= 101) {
System.out.println("Too high!");
else
switch(score / 10)
{
case 10:
case 9: System.out.println("Letter grade is A\n");
break;
case 8: System.out.println("Letter grade is B\n");
break;
case 7: System.out.println("Letter grade is C\n");
break;
case 6: System.out.println("Letter grade is D\n");
break;
default: System.out.println("Letter grade is F\n");
}
}
}
}
Re: Help with Average and Variables Please =)
If you want to figure out the average. First know the formula.. Surely you know this (sum of values / # of values).. I'm sure you can go from there.. (if you wrote this code on your own)
G'luck, comment back if you have any questions.
Re: Help with Average and Variables Please =)
Well, yes i believe its something like
Code :
int average = (count / scores)
but i couldnt remember where to put it, also i couldn't remember how to display max score =S
help please. i tried for hours haha. my minds been blank but yes i did write this
Re: Help with Average and Variables Please =)
Well, you have the variables switched around.. It would be this
Code :
int average = scoreSum/count
In order to get the Sum of the Scores, you have to add them to a variable each time you get a score in.
So basically, here's the logic:
I have a count variable of length (let's make something up) 5.
Therefore, I must have 5 scores.
If I want to get the average, I must find the sum of the scores.
The score variable changes every time I run my loop, so simply multiplying the score by 5 at the end won't work.
So in all, I must find a way that I can add each individual score to "something" 5 times... You can go from here, it's best to learn from Trial & Error
And if you want to display the maximum grade, you have to have a variable that changes every time a higher number comes..
This concept is a little harder, but first, try to get the Average section working.