• C

Coin

A novice question. I have to ask the user to input float amount between 0.00 and $100.00. Then printout number of TWENTIES, TENS, FIVES, ONES, quarters, dimes, nickels and pennies. Any help is appreciated. This is the way I approached it: (formatting from float to int is a problem).

main()
{
float amount_uner;
float amount_pennies;
scanf("d", &amount_user);
printf("Enter Dollar amount between $0.00 and $100.00"\n);
amount_pennies=amount_user*100;
if (amount_user >100.00 or <0.00)
printf("wrong, Please try inputing your request amount in the form of $###.## \n");
if (amount_user>=2000)
{
Twenties=amount_user/2000;
Twenties=amount_user%2000;
Tens=  /* continure until we run out of money */

How about the user put in 0.25 or an amount less than $20.00
catalyst19002800Asked:
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.

q2guoCommented:
#include <stdio.h>

int main()
{
    float bill[8] = {20, 10, 5, 1, 0.25, 0.1, 0.05, 0.01};
    int billnum[8] = {0,0,0,0,0,0,0,0};
    float amount_user;

    printf("Enter Dollar amount between $0.00 and $100.00: ");
    scanf("%f", &amount_user);

    while (amount_user != 0)
    {
         if (amount_user > 20) {
              amount_user -= 20;
              billnum[0]++;      
         }
         elseif (amount_user > 10) {
              amount_user -= 10;
              billnum[1]++;      
         }
         elseif (amount_user > 5) {              
              amount_user -= 5;
              billnum[2]++;      
         }

         elseif (amount_user > 1) {
              amount_user -= 1;
              billnum[3]++;      
         }
         elseif (amount_user > 0.25) {
              amount_user -= 0.25;
              billnum[4]++;      
         }
         elseif (amount_user > 0.1) {
              amount_user -= 0.1;
              billnum[5]++;      
         }
         elseif (amount_user > 0.05) {
              amount_user -= 0.05;
              billnum[6]++;      
         }
         elseif (amount_user > 0.01) {
              amount_user -= 0.01;
              billnum[7]++;      
         }
         else {
              break;
         }
    }

    printf("There are %d twenty dollar bills.\n", billnum[0]);
    printf("There are %d ten dollar bills.\n"   , billnum[1]);
      ....
    printf("There are %d one cents.\n"   , billnum[7]);
}
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
q2guoCommented:
Sorry, all the ifs should read

if (amount_user => 20) {

I forget the equal sign.
0
catalyst19002800Author Commented:
Although the solution is useful but I am not suppose to use arrarys in this problem. Is there alternatives solutions by using nested loops or Case staments: (Thanks so much, You are great. Once I get a chance, I will read more on the details of this site and see what I need to do to support it.
0
q2guoCommented:
I didn't test this program out. so, let me know if it works.

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

int main()
{
   float amount_user;
   float i=20;
   int a=0 , b=0 , c=0, d=0, e=0, f=0, g=0, h=0;

   printf("Enter Dollar amount between $0.00 and $100.00: ");
   scanf("%f", &amount_user);

   while (amount_user != 0)
   {
      if ((amount_user - i ) >= 0 )  {
        switch (amount_user - i) {
          case (amount_user - 20) : a++;
          case (amount_user - 10) : b++;
          case (amount_user - 5) : c++;
          case (amount_user - 1) : d++;
          case (amount_user - 0.25) : e++;
          case (amount_user - 0.1) : f++;
          case (amount_user - 0.05) : g++;
          case (amount_user - 0.01) : h++;        
        }

      } else  {
        switch (amount_user - i) {
          case (amount_user - 20) : i = 10;
          case (amount_user - 10) : i = 5;
          case (amount_user - 5) : i = 1;
          case (amount_user - 1) : i = 0.25;
          case (amount_user - 0.25) : i = 0.1;
          case (amount_user - 0.1) : i = 0.05;
          case (amount_user - 0.05) : i = 0.01;
          case (amount_user - 0.01) : break;        
        }
      }
    }
    printf("There are %d twenty dollars.\n" , a);
       ....
    printf("There are %d one cents.\n" , h);
}
0
catalyst19002800Author Commented:
/* Here is a modified version of your suggestion that I think is required. However; it does not work very good. Also I have to get the least number of bills and coins (another words larger denominations) */
/*Thanks*/


#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
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
C

From novice to tech pro — start learning today.