Now it's telling me that highestDonation isnt initialised. I don't know how to intitialise this variable, I know how, but don't know what I should be setting it to. :(
Printable View
Now it's telling me that highestDonation isnt initialised. I don't know how to intitialise this variable, I know how, but don't know what I should be setting it to. :(
Do the same as these:Code :
...donationQuantity=0, maxDonation=0 ...
Here is my code now, it\'s working. Thanks for your help, one more thing, the condition is always going to be true. So why won\'t it work without the IF Statement?
Code java:
public class Donations { public static void main(String[] args) { Scanner keyboard= new Scanner (System.in); String donorName; double newDonation, donationQuantity=0, maxDonation=0, highestDonation=0; String highestDonor=""; do { System.out.println("\n"); System.out.println("Please enter donation amount"); //PRINT newDonation=keyboard.nextInt(); System.out.println("Please enter your name"); //PRINT donorName=keyboard.next(); if(newDonation>highestDonation) { highestDonation=newDonation; highestDonor=donorName; } donationQuantity=donationQuantity+1; maxDonation +=newDonation; } while (maxDonation<500); System.out.println("It took " + donationQuantity + " donations to reach the £500"); System.out.println("Highest donation amount was " + highestDonation + " by " + highestDonor); }//main }//class
Can you explain what "the condition" is you are talking about? And why it is always going to be true.Quote:
the condition is always going to be true. So why won\'t it work without the IF Statement?
If newDonation <= 0, then highestDonation = newDonation. Since you\'re comparing whether newDonation is greater but not equal to highestDonation, the condition evaluates to false.