Originally Posted by pass_prime
Code:
/* Assignment 4 - Bonus
Variables: int MaxCoins, NumCoin,
float CurrentAmt,AmtRemaining
*/
#include <stdio.h>
#include<stdlib.h>
#define TOONIE 2.00
#define LOONIE 1.00
#define JOHNIE 1.23
#define QUARTER 0.25
#define DIME 0.10
#define NICKEL 0.05
#define PENNY 0.01
int main()
{
float Currentamt,AmtRemaining;
int i,maxCoins,NumCoins,maxJohnie;
int NumToonie,NumLoonie,NumJohnie,NumQuarter,NumDime,N umNickel,NumPenny;
Currentamt = 0;
maxCoins = 10000;
maxJohnie/Currentamt;
printf("\nEnter an amount of money that is less than $1000.00 (Enter a 0 to quit): ");
scanf("%f",&Currentamt);
while(Currentamt != 0)
{
AmtRemaining = Currentamt;
for(i = 0; i <= maxJohnie; i++)
{
AmtRemaining = AmtRemaining - 1.23;
NumCoins = NumCoins + 1;
NumJohnie = NumJohnie + 1;
}
while (AmtRemaining >= TOONIE)
{
AmtRemaining = AmtRemaining - 2;
NumCoins = NumCoins + 1;
NumToonie = NumToonie + 1;
}
while (AmtRemaining >= LOONIE)
{
AmtRemaining = AmtRemaining - 1;
NumCoins = NumCoins + 1;
NumLoonie = NumLoonie + 1;
}
while (AmtRemaining >= QUARTER)
{
AmtRemaining = AmtRemaining - .25;
NumCoins = NumCoins + 1;
NumQuarter = NumQuarter + 1;
}
while (AmtRemaining >= DIME)
{
AmtRemaining = AmtRemaining - .10;
NumCoins = NumCoins + 1;
NumDime = NumDime + 1;
}
while (AmtRemaining >= NICKEL)
{
AmtRemaining = AmtRemaining - .05;
NumCoins = NumCoins + 1;
NumNickel = NumNickel + 1;
}
while (AmtRemaining >= PENNY)
{
AmtRemaining = AmtRemaining - .01;
NumCoins = NumCoins + 1;
NumPenny = NumPenny + 1;
}
printf("\nThe least amount of coins required to make up $%f is %d",Currentamt,NumCoins);
printf("\nThe coins need are: ");
if(NumToonie != 0)
printf("\n %d \t Toonies \t = \t $%f",NumToonie,NumToonie*TOONIE);
if(NumLoonie != 0)
printf("\n %d \t Loonies \t = \t $%f",NumLoonie,NumLoonie*LOONIE);
if(NumJohnie != 0)
printf("\n %d \t Johnies \t = \t $%f",NumJohnie,NumJohnie*JOHNIE);
if(NumQuarter != 0)
printf("\n %d \t Quarters \t = \t $%f",NumQuarter,NumQuarter*QUARTER);
if(NumDime!= 0)
printf("\n %d \t Dimes \t = \t $%f",NumDime,NumDime*DIME);
if(NumNickel != 0)
printf("\n %d \t Nickel \t = \t $%f",NumNickel,NumNickel*NICKEL);
if(NumPenny != 0)
printf("\n %d \t Pennys \t = \t $%f",NumPenny,NumPenny*PENNY);
printf("\n %d coins \t \t = \t $%f", NumCoins,Currentamt);
printf("\nEnter an amount of money that is less than $1000.00 (Enter a 0 to quit): ");
scanf("%f",&Currentamt);
if(NumCoins <= maxCoins)
{ maxCoins = NumCoins;
NumJohnie = i;
}
}
getchar();
return 0;
}
well, the code which is nin bold should be like this
Code:
maxJohnie/=Currentamt; // which is equal to maxJohnie=maxJohine/Currentamt
s.s.harish