Computer Science Canada Help plz |
Author: | indianstorm [ Sat Nov 06, 2004 11:30 am ] | ||
Post subject: | Help plz | ||
Write a program that reads in a number of cents. The program will write out the number of dollars and cents, like this: D:\users\default>java Dollars Input the cents: 324 That is 3 dollars and 24 cents. (For this program you will use integer arithmetic and will need to avoid floating point arithmetic. Review the integer remainder operator % if you are unsure how to proceed.) ___________________________________________________________
____________________________________________________________ Plz help me witht that |
Author: | indianstorm [ Sat Nov 06, 2004 11:46 am ] |
Post subject: | |
nvm i got it __________ import java.io.*; class Calcofmoney { public static void main (String[] args) throws IOException { InputStreamReader inStream = new InputStreamReader (System.in); BufferedReader stdin = new BufferedReader (inStream); String inData; double num; double beamer, streamer; System.out.println ("Input the amount of money:"); inData = stdin.readLine (); num = Integer.parseInt (inData); streamer= num % 100; beamer = (num - (streamer))/100; System.out.println ("That is " + beamer + " dollars and " + streamer + " cents "); } } |
Author: | wtd [ Sat Nov 06, 2004 3:16 pm ] | ||||||||
Post subject: | |||||||||
You declare "num", like thus:
But you use it as an integer:
And you use the modulus operator on it:
Clearly "streamer", "beamer", and "num" should be declared as integers, not doubles. Also, in Java you don't need to declare all of your variables at the beginning of a function. With no other changes made to correct it:
|
Author: | wtd [ Sat Nov 06, 2004 3:19 pm ] |
Post subject: | |
By the way, it's nice to see you using standard Java. |