@ ALL:
Hi thank you for your reply. Sorry I did not specify that I cannot use advanced coding. I need simple codes for this.
Someone gave me this advice:
you get the dollars by taking int(cents / 100)
you get the cents by taking cents mod 100
you have to use if statement to check if it's 0 cents (don't show it), 1 cent (use cent instead of cents) or more (use cents)
But I do not know how to use these.
This is my program that outputs the "
The total amount in dollar is 1.1":
import java.io.*;
public class CentsDollar {
public static void main (String[]args) {
BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
String x="";
try {
System.out.println("Enter amount in nickel: ");
x = input.readLine();
int nickelin = Integer.parseInt(x);
System.out.println("Enter amount in penny: ");
x = input.readLine();
int penniesin = Integer.parseInt(x);
double pennies = (nickelin*5)+(penniesin);
double nickel = (pennies/5);
System.out.println("You entered " +nickelin+ " nickels and " +penniesin+ " pennies.\n");
System.out.println("The total amount in penny is "+pennies+".");
System.out.println("The total amount in nickel is "+nickel+".\n");
System.out.println("Converting the amount of nickel and penny into dollar...\n\n");
double dollar = (pennies/100);
System.out.println("The total amount in dollar is " +dollar+"." );
}
catch (IOException e) {
System.out.println("Error!");
}
}
}
Where do I insert the if statement? How do I use the "mod"?