473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Assign variables to numbers left of decimal and right

Edit: Ah, never mind. I feel silly. I just needed to convert amount into an integer.
I am having a little trouble figuring out how to assign a variable (dollars) to the numbers left of the decimal and how to assign a variable (cents) to the right of the decimal. The only parts of the code I can modify are those 2 assignment statements because it is a homework question. The user inputs something like 123.45

Thanks for any help.

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. public class ApplicationSkel
  3. {
  4.  
  5.   public static void main(String[] args)
  6.   {
  7.     double amount;
  8.      int dollars, cents;
  9.      Scanner scan = new Scanner(System.in);
  10.  
  11.      System.out.print("Enter your purchase $");
  12.      amount = scan.nextDouble();
  13.  
  14.      dollars = ________;
  15.      cents  = ________;
  16.  
  17.      System.out.print("You entered " + dollars + " dollars and " + cents + "."); 
  18.  
  19.   }
  20. }
  21.  
Feb 17 '09 #1
1 2032
horace1
1,510 Expert 1GB
try casting amount to an int?
Feb 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
4
by: Sam Kong | last post by:
Hello! I wonder if there's a good way to make a function that calculates 2 big numbers (whole numbers) expressed as strings and return a result string with the value of a number? For example:...
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
9
by: WyattM | last post by:
i have been trying to get this code to work but keep getting errors. what am I doing wrong? the errors that I am getting are: 'Public Property Left() As Integer' has no parameters and its return...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.