Looked through my code several times and cant seem to fins why the program continually takes the value of coin to be l or L making it always take 1.00 of the total. I'm looking for help with that as well as how to display my float number to only 2 decimal points. I think I remember you being able to use modulus but can't remember exactly how. Thanks in advance.
Code:
#include <stdlib.h>
int main()
{
char coin, l , L , q , Q , d , D , n , N ;
float total = 0, tobepaid = 3.50, change;
printf("Welcome to the world of deep-fried Twinkies\n Each Twinkie costs $3.50\n\n");
while( total <= 3.50)
{
printf("$%f\n\n" , tobepaid - total);
printf(" L or l for loonie\n Q or q for quarter\n D or d for dime\n N or n for nickel\n");
scanf("%c" , &coin);
getchar();
if((coin = 'l')||(coin = 'L'))
{
total = total + 1.00;
}
else if((coin = 'q')||(coin = 'Q'))
{
total = total + 0.25;
}
else if((coin = 'd')||(coin = 'D'))
{
total = total + 0.10;
}
else if((coin = 'n')||(coin = 'N'))
{
total = total + 0.05;
}
else
{
printf(" This machine only accepts Loonies, Quarters, Dimes and Nickels");
}
}
change = total - tobepaid;
printf(" Enjoy your Twinkie!\n You have %f in change\n" , change);
system("pause");
return 0;
}