+ 8

help me to fix this code :(

int mark[] = new int[3]; int i; float sum=0; float avg; Scanner scan = new Scanner(System.in); System.out.println("Enter Score For 3 Test For Student num 1: "); for(i=0; i<3; i++) { mark[i] = scan.nextInt(); sum = sum + mark[i]; } avg = sum/3; Scanner sc= new Scanner(System.in); System.out.println("Average Marks = " +avg); System.out.println("------------"); System.out.println("Enter Score For 3 Test For Student num 2: "); for(i=0; i<3; i++) { mark[i] = scan.nextInt(); sum = sum + mark[i]; } avg = sum/3; System.out.print("Average Marks = " +avg);

28th Apr 2017, 5:37 AM
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏ - avatar
10 Respuestas
+ 12
*Bangs hammer on phone hoping it fixes somehow*
28th Apr 2017, 5:38 AM
Ahri Fox
Ahri Fox - avatar
+ 9
I try to make like this and it take from me one week :( BUT how much i try how much it make very angry it is repeated for each test score! How many students do you have: 2 How many test scores per student: 3 Student Number 1 ------------------------- Enter Score of Test 1 : Enter Score of Test 2 : Enter Score of Test 3 : The average for student number 1 is Student Number 2 ------------------------- Enter Score of Test 1 : Enter Score of Test 2 : Enter Score of Test 3 : The average for student number 2 is
28th Apr 2017, 5:43 AM
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏ - avatar
+ 9
no :) this a challenge Q
28th Apr 2017, 8:08 AM
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏ - avatar
+ 8
Thank you very much ONE more Q How about this How many students do you have: 2 How many test scores per student: 3 how to make it!!
28th Apr 2017, 7:57 AM
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏ - avatar
+ 7
I already insert the first one :)
28th Apr 2017, 7:13 AM
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏ - avatar
+ 6
Which one exactly?
28th Apr 2017, 6:02 AM
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏
‏‪‏‪‏‪‏‪‏‪Lamiya‬‏‬‏‬‏‬‏‬‏ - avatar
+ 5
Heres the fix.. Since the sum value after the first loop will have some value,since its life time is throughout the program,its value is continued in the 2nd loop and it messes up the avg of 2nd student loop. so before starting the 2nd loop initialize the sum=0. and it works fine.. https://code.sololearn.com/cYv6ruy4Du89/?ref=app
28th Apr 2017, 7:48 AM
Manideep
Manideep - avatar
+ 2
Insert your code so that it will be easy for us to help..
28th Apr 2017, 7:04 AM
Manideep
Manideep - avatar
+ 2
is this your homework :0 try to figure it on your own bro,You cant learn if u wont trace your programs.take a pen and paper :0
28th Apr 2017, 8:06 AM
Manideep
Manideep - avatar
+ 1
Try to give value to avg variable in the first.
28th Apr 2017, 5:56 AM
Biobii
Biobii - avatar