-1
Consider four coins, 25 cents, 10, 5 and 1. Build a C program that asks the user how much he wants to receive in change and then print out the amount of coins needed to pay the change, always delivering as few coins as possible. The program must have a loop that forces the user to put a positive value.
source:
#include <cc50.h>
#include <stdio.h>
int main (void)
{
int a = 25;
int b = 10;
int c = 5;
int d = 1;
float f = 0;
do
printf("Quanto de troco deseja receber? ");
f = GetFloat();
while ( f < 0 );
if ( f == 0 )
printf("Obrigado volte sempre!\n");
if ( f > 0 )
printf("Este troco exige %.2f moedas.\n", f);
}
Thank you so much for the syntax tip, I didn’t know. About the function, I’m obliged to do with Getfloat(), it’s a course exercise.
– Matheus
No problems, I just couldn’t test because I don’t have the cc50.h file that should contain this function, so I used scanf which is available in C.
– Antonio