how can I get an output value of equal amount.

How get a different value in the output? Example I input  integer of 100 pennies an get a dollar, but zero for the quarters pennie, dimes, nickels. How can I get an equal value for all. Example quarters 4, dimes 10, nickels 20, pennies 100.

import java.util.*;
public class realcoins
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("type an interger in pennies");
int cents = input.nextInt();
int dollars = cents / 100;
int remaining = cents % 100;
int quarters = remaining / 25;
remaining = remaining % 25;
int dimes = remaining / 10;
remaining = remaining % 10;
int nickels = remaining / 5;
int pennies = remaining % 5;
System.out.println(cents + " cents is=");
System.out.println(dollars + " dollars " + quarters + "quarters"+ dimes + "dimes" + nickels + "nickels" + "and" + pennies + "pennies");
}

}
waltbaby315Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:

int remaining = cents % 100;

remaiing is 100(modulo 100) = 0
then you divied remaiang by any number - becomes 0 all the time of course
0
for_yanCommented:
int dollars = cents / 100;

int quarters = cents/25;

int dimes = cents/10;

int nickels = cents/5;

then you'll have different values
0
for_yanCommented:
and

int pennies = cents/100;

(not ddivied by 5 as you have)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

waltbaby315Author Commented:
Is there any way I can change it so  they all will be equal
0
for_yanCommented:
You mean you want equal values in the result string? equal number of quarters, dimes, etc. ?
0
for_yanCommented:
if you start from input value:

100 + 25 + 10 + 5 + 1 = 141

and
indeed use remaining then you'll get reasonable
program:

import java.util.*;
public class realcoins 
{
public static void main(String[] args) 
{
Scanner input = new Scanner(System.in);
System.out.println("type an interger in pennies");
int cents = input.nextInt();
int dollars = cents / 100;
int remaining = cents - dollars*100;
int quarters = remaining/25;
remaining = remaining - 25*quarters;
int dimes = remainig/10;
remnaming = remaninig-10*dimes;
and so on...


System.out.println(cents + " cents is=");
System.out.println(dollars + " dollars " + quarters + "quarters"+ dimes + "dimes" + nickels + "nickels" + "and" + pennies + "pennies");
}

} 

Open in new window


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.