User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 329,084 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,564 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 147 | Replies: 5
Reply
Join Date: May 2008
Posts: 1
Reputation: s080072 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
s080072 s080072 is offline Offline
Newbie Poster

need help with for loop

  #1  
6 Days Ago
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);
}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: New Hampshire
Posts: 3,091
Reputation: jasimp is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 15
jasimp's Avatar
jasimp jasimp is offline Offline
Posting Sensei

Re: need help with for loop

  #2  
6 Days Ago
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 : 6 Days Ago at 7:17 pm.
A room without books is like a body without a soul.
There will be water if ka wills it.
Go then, there are other worlds than these.
Reply With Quote  
Join Date: May 2008
Posts: 3
Reputation: xandres is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xandres xandres is offline Offline
Newbie Poster

Re: need help with for loop

  #3  
6 Days Ago
Also try putting the post with the tags. It becomes more easy to read and identify problems

  1. int example
Reply With Quote  
Join Date: May 2008
Posts: 16
Reputation: alpe gulay is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
alpe gulay alpe gulay is offline Offline
Newbie Poster

kindly state it clear...

  #4  
6 Days Ago
if you illustrate me the problem clearly maybe i can help...I didn't get the problem...
Reply With Quote  
Join Date: May 2008
Posts: 1
Reputation: devang.adeshara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
devang.adeshara devang.adeshara is offline Offline
Newbie Poster

Re: need help with for loop

  #5  
2 Days Ago
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();
}
}

}
Reply With Quote  
Join Date: Aug 2007
Location: New Hampshire
Posts: 3,091
Reputation: jasimp is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 15
jasimp's Avatar
jasimp jasimp is offline Offline
Posting Sensei

Re: need help with for loop

  #6  
2 Days Ago
Don't do their work for them.
A room without books is like a body without a soul.
There will be water if ka wills it.
Go then, there are other worlds than these.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 6:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC