Thanks and bear with me. It's all new and I am teaching myself.
/* develop a program that accepts a dollar amount (in cents) and then computes
the number of quarters, dimes, nickels, and pennies needed. The solution must
produce the smallest number of coins possible for the given dollar amount*/
#include <stdio.h>
main()
{
int c,q = 0, d = 0, n = 0, p = 0; /* I had to initialize my actual coin
counts to zero, else I got some pretty
amazing numbers*/
printf( "Please enter an amount ( in cents ):" );
scanf( "%d", &c );
getchar();
while ( c >= 25 ){
q++;
c = c - 25; /* could I use c -= 25 format here and
in following statements?*/
}
printf( "* You will need %d quarters.\n", q);
while ( c >= 10 ){
d++;
c = c - 10;
}
printf( "* You will need %d dimes.\n", d);
while ( c >= 5 ){
n++;
c = c - 5;
}
printf( "* You will need %d nickels.\n", n);
while ( c >= 1 ){
p++;
c = c - 1;
}
printf( "* You will need %d pennies.\n", p);
getchar();
}
This post has been edited by Dogmasur: 28 July 2008 - 06:30 PM

New Topic/Question
Reply




MultiQuote



|