# This is my code for greedy how do i convert it to decimal. I want to take the final value of coins_4 / 100. But I get an error

Or I could use Getfloat then times by 100. But I get an error. I think this makes more sense.

``````#include <stdio.h>
#include <cs50.h>

int main(void)

{
int amount;
int change = 0, change_2, change_3, change_4 = 0, change_total;
int  coins, coins_2,  coins_3,  coins_4;
//calculate change needed and how many coins used while using least amount coins needed

do
{
printf ("please pick an positive number\n");
coins = GetInt();
amount = coins;
}
while (amount < 0); //  positive number

if (amount >  25)  // greater 25 cents
{
coins = coins % 25;
change = (amount - coins) / 25;
}
else
{
coins = coins % 25;
change = amount /25;

}

if (coins < 25 && coins > 10) // greater 10 cents
{
coins_2 = coins % 10;
change_2 = (coins - coins_2) / 10;
}
else
{
coins_2 = coins % 10;
change_2 = coins / 10;

}

if (coins_2 < 10 && coins_2 > 5) // greater 5 cents
{
coins_3 = coins_2 % 5;
change_3 = (coins_2 - coins_3) / 5;
}
else
{
coins_3 = coins_2 % 5;
change_3 = coins_2 / 5;
}

if (coins_3 < 5 && coins_3 > 1)
{
coins_4 = coins_3 % 1;
change_4  = coins_4 / 1;
change_total = change + change_2 + change_3;
printf (" coins:%d\nchange:%d\n:", coins_4, change_total);
}
else
{
coins_4 = coins_3 % 1;
change_4 = coins_3 / 1;
change_total = change + change_2 + change_3 + change_4;
printf (" coins:%d\nchange:%d\n:", coins_4, change_total);
}
}

#include <stdio.h>
#include <cs50.h>

int main(void)
{
int amount;
int change = 0, change_2, change_3, change_4 = 0, change_total;
float coins;
int coins_2, coins_3, coins_4              ;
//calculate change needed and how many coins used while using least amount coins needed
do
{
printf ("please pick an positive number\n");
coins = GetFloat);
coins =coins * 100;
amount = coins;
}
while (amount < 0);     //  positive number

if (amount >  25)  // greater 25 cents
{
coins = coins % 25;
change = (  amount - coins  ) / 25;
}
else
{
coins = coins % 25;
change = amount /25;
}

if (coins < 25  && coins > 10) // greater 10 cents
{
coins_2 = coins % 10;
change_2 = (coins - coins_2) / 10 ;
}
else
{
coins_2 = coins % 10;
change_2 = coins / 10;

}

if (coins_2 < 10 && coins_2 > 5) // greater 5 cents
{
coins_3 = coins_2 % 5;
change_3 = (coins_2 - coins_3) / 5;
}
else
{
coins_3 = coins_2 % 5;
change_3 = coins_2 / 5;

}

if (coins_3 < 5 && coins_3 > 1 )
{
coins_4 = coins_3 % 1;
change_4  = coins_4 / 1   ;
change_total = change + change_2 + change_3;
printf (" coins:%d\nchange:%d\n:", coins_4 / 100, change_total);
}
else
{

coins_4  = coins_3 % 1;
change_4 = coins_3 / 1;
change_total = change + change_2 + change_3 + change_4;
printf (" coins:%d\nchange:%d\n:", coins_4 / 100, change_total);
}
}
``````

Compiler output:

``````greedy.c:16:11: error: assigning to 'float' from incompatible type 'float (*)(void)'
coins = GetFloat);
^ ~~~~~~~~
greedy.c:29:23: error: invalid operands to binary expression ('float' and 'float')
coins = coins % 25;
~~~~~ ^ ~~
greedy.c:35:27: error: invalid operands to binary expression ('float' and 'float')
coins = coins % 25;
~~~~~ ^ ~~
greedy.c:45:29: error: invalid operands to binary expression ('float' and 'float')
coins_2 = coins % 10;
~~~~~ ^ ~~
greedy.c:50:29: error: invalid operands to binary expression ('float' and 'float')

coins_2 = coins % 10;
``````
• please specify the error you get and at what line. Apr 30, 2017 at 5:48
• I think I need to use fmod() because there is a float % float. How do I use fmod when it is not in a printf line of code? Apr 30, 2017 at 20:43
• u can use the % operator on real numbers. You can explicitly change type to int using (int) operator on the floating point variables May 1, 2017 at 4:28