So i got this assignment in computer science that computes change from money given etc. etc.
Anyways what i need help with is at the end of the program it asks you if you want to run the program again. I got it to run it again one more time with an if statement but it only runs on more time and it runs again no matter what you type in when it asks you if you want to run it again.
How would i put it in a loop and mke it run over and over and if they type no it ends the program?
All help is appreciated very much
import java.io.*; public class Temp2 { public static void main(String[] args) throws IOException { BufferedReader input= new BufferedReader(new InputStreamReader(System.in)); double prc; double rcvd; int dllrs,qrtrs,dms,nckls,pnns; System.out.println("Enter Amount Recieved"); rcvd=Double.parseDouble(input.readLine()); System.out.println("Enter Price Of Item"); prc=Double.parseDouble(input.readLine()); double chngdue=rcvd-prc; System.out.println("Change Due"+" "+chngdue); double lftvr; dllrs=(int)chngdue/1; System.out.println("Dollars:"+" "+dllrs); lftvr=chngdue-dllrs; qrtrs=(int)(lftvr/.25); System.out.println("Quarters:"+" "+qrtrs); lftvr-=(qrtrs*.25); dms=(int)(lftvr/.10); System.out.println("Dimes:"+" "+dms); lftvr-=(dms*.10); nckls=(int)(lftvr/.05); System.out.println("Nickels:"+" "+nckls); lftvr-=(nckls*.05); pnns=(int)(lftvr/.01); System.out.println("Pennies:"+" "+pnns); System.out.println("Would you like to run the program again"); String answer="yes"; answer=input.readLine(); if (answer=="yes") System.out.println("OK"); System.out.println("Enter Amount Recieved"); rcvd=Double.parseDouble(input.readLine()); System.out.println("Enter Price Of Item"); prc=Double.parseDouble(input.readLine()); System.out.println("Change Due"+" "+chngdue); System.out.println("Dollars:"+" "+dllrs); System.out.println("Quarters:"+" "+qrtrs); System.out.println("Dimes:"+" "+dms); System.out.println("Nickels:"+" "+nckls); System.out.println("Pennies:"+" "+pnns); System.out.println("Would you like to run theprogram again"); answer=input.readLine(); } }