Hi,
I am required to write a program that counts the minimum amount of coins required to return a change, i.e. if user inputs .57 for example, the program has to output number 5 (two quarters, one dime, one nickel).
What I have so far is this (
Code:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
//creates a infinite loop that checks if the value is valid
while(1)
{
//get a float value from the user and convert it to cents
printf("O hai! How much change is owed?\n");
float v = GetFloat();
v = v*100;
int c = (int) v;
//quarters
if(c >= 25)
{
int count = 0;
count = (c / 25);
c = c % 25;
printf("%d\n", count);
}
//dimes
if(c >= 10)
{
int countd = 0;
countd = count + (c / 10);
c = c % 10;
printf("%d\n", countd);
}
break;
}
return 0;
}
Quarters part works as it should (If I remove the dimes part, compile it, run it and input .50 for example, it spits out 2), however what I do not understand is why I cannot use the "count" from quarters and then add dimes to it (c / 10).
If I try to compile it like this I get an error message saying that
Code:
greedy.c:41:13: error: use of undeclared identifier 'count'; did you mean 'countd'?
Any help greatly appreciated. Thank you