0

Like mentioned in the title, I get this "expected expression" error when I try to convert my amount from float into int type. Am I doing the conversion wrong ? Or is there something else I'm missing ?

Thank you !

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

int main(void)

{
    float amount;
    
    //ask user for input
    do
    {
        amount = get_float("Please pay: ");
    }
    while(amount < 0);
    
    //converting dollars to cents
    amount = (amount * 100);
    printf("%f", amount);
    
    //how many 25c can I use
    int remainder = int(amount % 25);
    printf("%d", remainder);
}


  
0

Yes, it's an incorrect syntax for casting a var. I'm assuming that you want to cast amount as an int, since the modulo operation requires integers. To cast one type as another, the parentheses goes around the type cast keyword, not the var name, like this.

int remainder = (int)amount % 25;

Now, there's a possibility that this program is going to have other issues, but I'll let you find that on your own. Hint: round() is your friend.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |

You must log in to answer this question.

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