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.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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:...donationQuantity=0, maxDonation=0 ...
If you don't understand my answer, don't ignore it, ask a question.
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?
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.the condition is always going to be true. So why won't it work without the IF Statement?
If you don't understand my answer, don't ignore it, ask a question.
If newDonation <= 0, then highestDonation = newDonation. Since you're comparing whether newDonation is greater but not equal to highestDonation, the condition evaluates to false.