Im trying to calculate the average, but it discards the remainder.
Have a look.
//Reads a file, and gets the students name + 3 exam grades.
//Then calculates the average grade.
name = TextIO.getln();
grade1 = TextIO.getlnInt();
grade2 = TextIO.getlnInt();
grade3 = TextIO.getlnInt();
average = (grade1+grade2+grade3)/3;
System.out.printf("The average grade for %s was %1.2f", name, average);
I've managed to work around it by just adding them up and dividing like this:
average = (grade1+grade2+grade3);
average = average / 3;
With this i can display the correct value.
I used jEdit, for my coding. And this is a question or "Test yourself" thingy from a book, and the solution uses the same code... so what did i do wrong ?
I figured it out :/ haha, sorry.
I forgot to put 3.0.
Nice forum by the way, maybe you guys will let me hang here in the newbie forums for a while ?
I don't think we could stop you from hanging here if you weren't. Though this community is free, and everyone is welcome.
As long as you're not looking for a handout, questions are accepted here. From the looks of it, you won't have a problem asking questions here.
You are more than welcome here, especially if you keep answering your own questions (and maybe a couple of questions from other newbies)!