Ahoj! Delam program kde uzvatel zada cisla a pak se nakone sectou a najdou maximalni a minimalni hodnotu. Mam zde ale logickou chybu. Kdyz zadam 4 ve vsech polickach + 1 bonus bod vyjde mi 17. Ma to ale byt 25. Pomuze mi prosim nekdo najit logickou chybu?
zde je muj kod
import java.io.*;
class P17_IBO {
static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
public static void main (String[] args) throws IOException {
//variables
String first,last,yn;
int i, slmark=0, hlmark=0, low=999, high=-999, bonus;
int sltotal=0, hltotal=0;
boolean done,rangeCheck;
done=false;
while (done==false) {
sltotal=0;
hltotal=0;
low=999;
high=-999;
System.out.println("Please enter FIRST name: ");
first=stdin.readLine ();
System.out.println("Please enter LAST name: ");
last=stdin.readLine ();
rangeCheck=false;
for (i=0;i<3;i++) {
slmark=0;
sltotal=0;
System.out.print("Please input SL subject mark " + (i+1) + ":");
slmark = validatedIntegerInput();
sltotal = sltotal + slmark;
rangeCheck=false;
while(rangeCheck==false) {
if ((slmark>0)&&(slmark<8)) {
rangeCheck=true;
sltotal = sltotal + slmark;
}
else {
System.out.print("Enter a SL mark from 1 - 7 "+ (i+1)+" :");
slmark = validatedIntegerInput();
}
}
if (slmark<low) {
low = slmark;
}
if (slmark>high) {
high = slmark;
}
}
for (i=0;i<3;i++) {
hlmark=0;
hltotal=0;
System.out.print("Please input HL subject mark " + (i+1) + ":");
hlmark = validatedIntegerInput();
hltotal = hltotal + hlmark;
rangeCheck=false;
while(rangeCheck==false) {
if ((hlmark>0)&&(hlmark<8)) {
rangeCheck=true;
hltotal = hltotal + hlmark;
}
else {
System.out.print("Enter a HL mark from 1 - 7 "+(i+1)+" :");
hlmark = validatedIntegerInput();
}
}
if (hlmark<low) {
low = hlmark;
}
if (hlmark>high) {
high = hlmark;
}
}
System.out.print("Enter bonus mark: ");
bonus = validatedIntegerInput();
bonus = bonus + sltotal + hltotal;
System.out.println(first+" "+ last);
System.out.println("Total marks is: " + bonus);
System.out.println("Lowest mark is: " + low);
System.out.println("Highest mark is: " + high);
if (bonus>=24) {
System.out.print("Diploma awarded\n");
}
else {
System.out.print("FAIL\n");
}
System.out.print("Do you want more students? (Y/N): ");
yn = stdin.readLine ();
if (yn.toUpperCase().startsWith("Y")){
done=false;
}
else {
done=true;
}
} }
public static int validatedIntegerInput() throws IOException
{
// local variables
int result=0;
boolean ok = false;
while (!ok)
{
try
{
result = Integer.parseInt(stdin.readLine());
ok = true;
}
catch (NumberFormatException error)
{
System.out.println("Please type a number");
ok = false;
}
}
return result;
}
}
Příspěvky odeslané z IP adresy 117.0.159.–
Honzik