Solved

Bills

Posted on 1998-02-13
6
223 Views
Last Modified: 2010-04-02
User enters dollar amount as float
output should be the highest number of bills and coins (TWENTIES, TENS, FIVES, ONES, quarters, dimes, nickels, pennies). Any help is appreciated.

#include <stdio.h>

void main()
{
      unsigned TWENTIES, TENS, FIVES, ONES, quarters, dimes, nickels, pennies;
      float amount_user;

      printf("Enter Dollar amount between $0.00 and $100.00:");
      scanf("%d", &amount_user);
      amount_user=amount_user*100;
      printf("%d, amount_user\n");

      while (amount_user !=0)
      {
            if(amount_user>=2000)
            {
                  amount_user=amount_user/2000;
                  
            }
            else if(amount_user>=1000)
            {
                  amount_user-=1000;
                  TENS++;
            }
            else if(amount_user>=500)
            {
            amount_user-=500;
            FIVES++;
            }
            else if(amount_user>=100)
            {
            amount_user-=100;
            ONES++;
            }
            else if(amount_user>=25)
            {
            amount_user-=25;
            quarters++;
            }
            else if(amount_user>=10)
            {
            amount_user-=10;
            dimes++;
            }
            else if(amount_user>=05)
            {
            amount_user-=5;
            nickels++;
            }
            else if(amount_user>=1)
            {
            amount_user-=1;
            pennies++;
            }
            else
            {
                  break;
            }
      }
      printf("There are %d TWENTIES\n", TWENTIES);
      printf("There are %d TENS\n", TENS);
      printf("There are %d FIVES\n", FIVES);
      printf("There are %d ONES\n", ONES);
      printf("There are %d quarters\n", quarters);
      printf("There are %d dimes\n", dimes);
      printf("There are %d nickels\n", nickels);
      printf("There are %d pennies\n", pennies);
}






0
Comment
Question by:catalyst19002800
6 Comments
 
LVL 3

Expert Comment

by:q2guo
ID: 1257247
catalyst19002800 what you mean by "the highest number of bills and coins".

0
 
LVL 5

Accepted Solution

by:
julio011597 earned 20 total points
ID: 1257248
I guess you mean "the best efficient" way to distribute the amount among bills and coins.

--//--
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
  unsigned int TWENTIES, TENS, FIVES, ONES, quarters, dimes, nickels, pennies;
  unsigned int amount_user;

  while(1)  {
    float tmp_amount;

    printf("Enter amount between $0.00 and $100.00: ");
    scanf("%f", &tmp_amount);
    if(tmp_amount >=0 && tmp_amount <= 100) {
      amount_user = (unsigned int)(tmp_amount * 100);
      break;
    }
  }

  TWENTIES = TENS = FIVES = ONES =
    quarters = dimes = nickels = pennies = 0;

  while(amount_user >= 2000) {
    amount_user -= 2000;
    TWENTIES++;
  }

  while(amount_user >= 1000) {
    amount_user -= 1000;
    TENS++;
  }

  while(amount_user >= 500) {
    amount_user -= 500;
    FIVES++;
  }

  while(amount_user >= 100) {
    amount_user -= 100;
    ONES++;
  }

  while(amount_user >= 25) {
    amount_user -= 25;
    quarters++;
  }

  while(amount_user >= 10) {
    amount_user -= 10;
    dimes++;
  }

  while(amount_user >= 5) {
    amount_user -= 5;
    nickels++;
  }

  while(amount_user >= 1) {
    amount_user -= 1;
    pennies++;
  }

  printf("There are %d TWENTIES\n", TWENTIES);
  printf("There are %d TENS\n", TENS);
  printf("There are %d FIVES\n", FIVES);
  printf("There are %d ONES\n", ONES);
  printf("There are %d quarters\n", quarters);
  printf("There are %d dimes\n", dimes);
  printf("There are %d nickels\n", nickels);
  printf("There are %d pennies\n", pennies);

  return EXIT_SUCCESS;
}
--//--

HTH, julio
0
 

Expert Comment

by:rsjetty
ID: 1257249
Your objective can be achieved in about 10 lines of C code, using a simple "for' loop
for more details , get back to me.
-rsjetty
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 

Expert Comment

by:rsjetty
ID: 1257250
Your objective can be achieved in about 10 lines of C code, using a simple "for' loop
for more details , get back to me.
-rsjetty
0
 

Author Comment

by:catalyst19002800
ID: 1257251
This was mostly correct but some of the answers were wrong and that was fixed. One too little peenies. Anyway, I played around with the last While(---) and got it fixed. Thanks for your help.
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1257252
Would you mind telling what was wrong, and what has been your fix?
0

Featured Post

Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to find a data that is pure string   or not in vb.net ? 9 103
Test against App 49 133
How to set environment variables in C 2 78
Handling string inputs in C/Linux 23 179
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now