-5

Does this make any sense?

I got stuck in here with 4 errors and it is because I didn't declared the ints q,d,n,p. But if I do so it'll keep sending me more errors.

There might be something about having mixed ints and floats.

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


int main(void)
{
    {
        printf("O hai! ");
    }
    float valueTotal, quarter, valueQuarter, dime, valueDime,nickel, valueNickel, penny, valuePenny; 
    do
    {
        printf("How much change is owed?\n");
        valueTotal = GetFloat();
    }
    while (valueTotal <= 0);


    for (float quarter = 0; valueTotal >= 0.25; quarter--)
    {
        valueQuarter = valueTotal - ( q * 0.25);
    }
    for (float dime = 0; valueQuarter >= 0.10; dime--)
    {
        valueDime = valueQuarter - ( d * 0.10);
    } 
    for (float nickel = 0; valueDime >= 0.05; nickel--)
    {
        valueNickel = valueDime - ( n * 0.05);
    }
    for (float penny = 0; valueNickel >= 0.01; penny--)
    {
        valuePenny = valueNickel - ( p * 0.01);
    }
    printf("q+d+n+p\n");
}
msk1
  • 1
  • 1

1 Answers1

1

I didn't declared the ints q,d,n,p.

This is exactly your problem - at least one of them, anyways. If these variables are undeclared, how in the world is the program/code supposed to evaluate something like q * 0.25 ? If I said "Hey man, what is x times 0.25?" You'd have absolutely no idea, or tell me that the answer depends on x. The same goes with this code.

You said:

But if I do so it'll keep sending me more errors.

I'm assuming you also need to initialize them (or, in layman's terms, set them equal to something ie. q = 0)

Also, none of your loop conditions are actually changing.... meaning they're infinitely looping. Make sure that the code inside your loop is actually helping you reach the goal of satisfying the loop condition; for example:

 for (float quarter = 0; valueTotal >= 0.25; quarter--)
    {
        valueQuarter = valueTotal - ( q * 0.25);
    }

valueTotal is ALWAYS going to be greater than 0.25 (if it is less than 0.25 to begin with) since you are never changing it at all.

Ricky Mutschlechner
  • 4,291
  • 2
  • 31
  • 36