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

int biggestCoin (int num);

int main (void){
    float userinput;
    int changeOwed, coins;

    do {
        userinput = get_float("How much do I owe you? \n");
    } while (userinput < 0);

    changeOwed = round(userinput * 100);
    coins = 0;

    do {
        biggestCoin(changeOwed);
        changeOwed = changeOwed - biggestCoin;
        coins++;
    } while (changeOwed < 0);

    printf("%i", coins);

    }

//returns biggest possible coin to return to customer based on remaining change owed
int biggestCoin(int changeOwed) {
    int penny = 1;
    int nickle = 5;
    int dime = 10;
    int quater = 25;

    if (changeOwed <= quater) {
        return quater;
    } else if (changeOwed <= dime) {
        return dime;
    } else if (changeOwed <= nickle) {
        return nickle;
    } else {
        return penny;
    }

}

1 Answer 1

1

In the line changeOwed = changeOwed - biggestCoin;, you subtract a function from an integer. I assume you meant changeOwed = changeOwed - biggestCoin(changeOwed) instead, subtracting the return value of the function call instead.

After fixing that compiler error, what happens in your code if someone enters 0?

2
  • Hey that resolved that error, thanks!! If I enter a zero I get: runtime error: signed integer overflow: -2147483625 - 25 cannot be represented in type 'int'. Apr 2, 2020 at 8:34
  • For 0, I would expect 0 coins. Maybe you should check whether your conditions make sense (and whether a do..while loop for the second part makes sense)
    – Blauelf
    Apr 2, 2020 at 8:55

You must log in to answer this question.

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