Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:45:44+00:00 2026-06-13T14:45:44+00:00

As usual, I’m just another highschooler desperate enough to resort to asking the question

  • 0

As usual, I’m just another highschooler desperate enough to resort to asking the question after lots of googling.

I’m working on one of them programs that can somewhat be applied in real life (but never are). In this case, a change counter that sums up the number of dimes, nickels, quarters and remaining cents and shows them in one sentence.

My problem is, I need to make a proper sentence format that uses commas and an “and” in the end, which I can’t manage with my very limited current knowledge.

  • Anywhere you see a division of currency is a variable that represents
    it (cents, dimes etc)
  • backupInput is the variable that holds the
    user’s chosen number of cents (anything from 1-100)

The part of my program concerned with what I want to ask is this:

    System.out.print(backupInput + ": ");

    // Outputting the quarters
    if (quarters > 0)
    {
      if (quarters == 1)
        System.out.print("one quarter, ");
      else
        System.out.print(quarters + " quarters, ");
    }

    // Outputting the dimes
    if (dimes > 0)
    {
      if (dimes == 1)
        System.out.print("one dime, ");
      else
        System.out.print(dimes + " dimes, ");
    }  

    // Outputting the nickels
    if (nickels > 0)
    {
      if (nickels == 1)
        System.out.print("one nickel, ");
      else
        System.out.print(nickels + " nickels ");
    }

    // Outputting the cents
    if (cents > 0)
    {
      if (cents == 1)
        System.out.print(" one cent");
      else
        System.out.print(cents + " cents ");
    }

The problem is, anything this outputs give the result of something like

7: 1 dime, 2 cents

While it’s supposed to be, according to the example format given:

7: 1 dime and 2 cents
65: 2 quarters, 1 dime and one nickel
66: 2 quarters, 1 dime, 1 nickel, and one cent

Keep in mind I tried nearly everything I could think of and in all my tries it was too inefficient and didn’t even work in all the cases. I’m not trying to save myself from work here. I just want to learn the concept behind doing it right.

That’s about it. The rest of the program works fine and dandy. If any of you could help me, please keep the answer easy to understand for a newbie like me so it’s easier to grasp the concept 🙂
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:45:45+00:00Added an answer on June 13, 2026 at 2:45 pm

    Sometimes it’s easier to break the problem down a bit. What I’d probably do is create an array of strings: [“2 quarters”, “1 dime”, “1 nickel”, “one cent”]

    Then look at how many (valid) array elements I had and loop through N-1 of the N elements, outputting the lines separated by commas. Then (assuming that there’s more than one array element) output “and” followed by the last array element.

    There are other ways that are “more efficient”, but I’ve been in this biz 40 years, and I’ll take “easy to understand and works” over “efficient” any day.

    (Of course, this isn’t the only way to skin this cat, and probably there are others that are equally simple, but that’s for you and others to invent.)

    (Note that it’s critical to avoid code that must decide, between everyone of your if statements, whether or not to insert “and”. When you repeat the same logic over and over again you tend to multiply your errors and create a maintenance nightmare.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

as usual I'm working with my messed up database and I found that there
The usual way to read a file in C++ is this one: std::ifstream file(file.txt,
As usual in PK and Fk relationship. I am having two tables one is
I have as usual common functionality as after sign up user receives confirmation mail
As usual the question comes from a first time user of Android. Its three
The usual: document.body.addEventListener('touchmove',function(event){event.preventDefault();},false); isn't working for me. I am trying to make my iPad
My usual workflow when working with git, is something like this: create a local
as usual i come here after testing around for hours and not having any
My usual way of working on web development is to split the project into
My usual hosting environment is a dedicated server, however for one project I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.