943,838 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 880
  • Java RSS
May 5th, 2008
0

need help with for loop

Expand Post »
import java.util.*;
public class changemakerj
{
static Scanner console=new Scanner (System.in);
static final double PRICE = 10.50;
public static void main (String[] Args)
{
double quantity,tprice,amtpaid,change1,chg$10,chg$5,chg$2,chg50,chg20,chg5,chg2,chg1;

System.out.println("Enter the quantity:");
quantity=console.nextInt();


System.out.printf("Total price %.2f.%n",tprice=quantity*PRICE,quantity);
System.out.println();

System.out.println("Amount paid");
amtpaid=console.nextDouble();
System.out.println();

;
System.out.printf("Change %.2f.%n",change1=amtpaid-tprice,amtpaid);
System.out.println();

chg$10=(int)(change1/10);
change1=change1 - (chg$10*10);
System.out.println((int)(chg$10)+ "10.00");


chg$5=(int)(change1/5);
System.out.println((int)(chg$5) + "5.00");
change1=change1 - (chg$5*5);

chg$2=(int)(change1/2);
System.out.println((int)(chg$2) + "2.00");
change1=change1 - (chg$2*2);

chg50=(int)(change1/0.5);
System.out.println((int)(chg50) + ":50cents");
change1=change1 - (chg50*0.5);

chg20=(int)(change1/0.2);
System.out.println((int)(chg20) + ":20cents");
change1=(int)change1 - (chg20*0.2);

chg5=(int)(change1/0.5);
System.out.println((int)(chg5) + ":5cents");
change1=change1 - (chg5*0.5);

chg2=(int)(change1/0.2);
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
s080072 is offline Offline
8 posts
since May 2008
May 5th, 2008
0

Re: need help with for loop

Specifically tell us what problems you are having, what you have tried and any errors you get. Read the announcement at the top of the forum. We can't read your mind and know what you need help with.
Last edited by jasimp; May 5th, 2008 at 8:17 pm.
Featured Poster
Reputation Points: 533
Solved Threads: 53
Senior Poster
jasimp is offline Offline
3,593 posts
since Aug 2007
May 5th, 2008
0

Re: need help with for loop

Also try putting the post with the tags. It becomes more easy to read and identify problems

java Syntax (Toggle Plain Text)
  1. int example
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xandres is offline Offline
6 posts
since May 2008
May 6th, 2008
0

kindly state it clear...

if you illustrate me the problem clearly maybe i can help...I didn't get the problem...
Reputation Points: 9
Solved Threads: 1
Light Poster
alpe gulay is offline Offline
45 posts
since May 2008
May 9th, 2008
0

Re: need help with for loop

import java.util.*;

public class ChangeMakerJ
{
static Scanner console = new Scanner(System.in);

static final double PRICE = 10.50;

public static void main(String[] Args)
{
boolean anotherBill = true;
double quantity, tprice, amtpaid, change1, chg$10, chg$5, chg$2, chg50, chg20, chg5, chg2, chg1;
for(;anotherBill
{
System.out.println("Enter the quantity:");
quantity = console.nextInt();

System.out.printf("Total price %.2f.%n", tprice = quantity * PRICE,
quantity);
System.out.println();

System.out.println("Amount paid");
amtpaid = console.nextDouble();
System.out.println();

;
System.out.printf("Change %.2f.%n", change1 = amtpaid - tprice, amtpaid);
System.out.println();

chg$10 = (int) (change1 / 10);
change1 = change1 - (chg$10 * 10);
System.out.println((int) (chg$10) + "10.00");

chg$5 = (int) (change1 / 5);
System.out.println((int) (chg$5) + "5.00");
change1 = change1 - (chg$5 * 5);

chg$2 = (int) (change1 / 2);
System.out.println((int) (chg$2) + "2.00");
change1 = change1 - (chg$2 * 2);

chg50 = (int) (change1 / 0.5);
System.out.println((int) (chg50) + ":50cents");
change1 = change1 - (chg50 * 0.5);

chg20 = (int) (change1 / 0.2);
System.out.println((int) (chg20) + ":20cents");
change1 = (int) change1 - (chg20 * 0.2);

chg5 = (int) (change1 / 0.5);
System.out.println((int) (chg5) + ":5cents");
change1 = change1 - (chg5 * 0.5);

chg2 = (int) (change1 / 0.2);

System.out.println("Want to add Another bill ? ");
console.nextBoolean();
}
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
devang.adeshara is offline Offline
1 posts
since May 2008
May 9th, 2008
0

Re: need help with for loop

Don't do their work for them.
Featured Poster
Reputation Points: 533
Solved Threads: 53
Senior Poster
jasimp is offline Offline
3,593 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JPanel's size and JButton
Next Thread in Java Forum Timeline: Collection ? <?>





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC