0

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;
3
  • please specify the error you get and at what line. Apr 30 '17 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?
    – Tom55555
    Apr 30 '17 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 '17 at 4:28
0

Recheck your data types of every variable and the operations your making with them ....I'll find the answer ..if not reply I'll notify ..happy coding ..

If found vote😉

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .