0

At first I solved and it works only with user check and not check50, so I tried to add the calculate functions and the get_cents but it wouldn’t print coins anymore. Please help!!

When it worked:

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

int main(void)
{
    int cents;
    do
    {
        // Ask user for change
        cents = get_int("Change owed: ");
    }
    while (cents <= 0);

    int coins = 0;

    // Quarters
    while (cents >= 25)
    {
        cents -= 25;
        coins++;
    }

    // Dimes
    while (cents >= 10)
    {
        cents -= 10;
        coins++;
    }

    //Nickels
    while(cents >= 5)
    {
        cents -= 5;
        coins++;
    }

    // Pennies
    while(cents >= 1)
    {
        cents -= 1;
        coins ++;
    }
    printf("Least amount of coins: %i\n", coins);
}

When it didnt work:

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

int get_cents(void)
{
    int cents;
    do
    {
        // Ask user for change
        cents = get_cents("Change owed: ");
    }
    while (cents <= 0);
    return cents;
}

// Quarters
int calculate_quarters(int cents);
{
    int quarters = 0;
    while (cents >= 25)
    {
        cents -= 25;
        quarters++;
    }
    return quarters;
}
// Dimes
int calculate_dimes(int cents);
{
    int dimes = 0;
    while (cents >= 10)
    {
        cents -= 10;
        dimes++;
    }
    return dimes;
}
//Nickels
int calculate_nickels(int cents);
{
    int nickels = 0;
    while(cents >= 5)
    {
        cents -= 5;
        nickels++;
    }
    return nickels;
}
// Pennies
int calculate_pennies(int cents);
{
    int pennies = 0;
    while(cents >= 1)
    {
        cents -= 1;
        pennies++;
    }
    return pennies;
}
    int coins = quarters + dimes + nickels + pennies;
    printf("%i/n", coins);
}

1 Answer 1

0

From the code, it looks like you just removed the main function. I'm guessing you're getting a compiler error here.

You must log in to answer this question.

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