0

include

include

int main(void) {

    printf("duration of shower in minutes :\n");
    int m = GetInt();
    printf("minutes : %i\n", m);

    int b = b;
    int bottles(int b);
    {
        return m * 12;
    }
    printf("bottles : %i\n", b);

}

so the above is my code. currently it only prompts the user for the number of minutes spent in shower and shows that minutes : //insert random value here. Why does it not run the code that allows for the number of bottles to be calculated via multiplication?

1 Answer 1

1

Right now your code is just printing m, bottles is only defined, it is never called.

If you want to declare a variable, but not initialize it, int b; is what you would write. int b = b; assigns a new variable (b) to the previous b, of which you have none.

In "int bottles(int b)", you're saying you want a function ('bottles') who will take an argument ('b'); what you probably don't see, however, is that b is not the same variable we just declared, b is another variable (more specifically, a parameter) that is declared inside the scope of our new function. b != b. That said, your bottles function should take an amount of minutes m as an input argument, not b or bottles. Lastly, even if your function was properly defined, you're still not calling it, as in something like printf("%i", bottles(m));.

All things considered there's multiple issues preventing your code from returning the correct value. Don't worry though, go back and watch Zamyla's walkthrough (again if you already have), write down the program in pseudo-code before you even attempt writing it in pure C, then write the entire program in int main, only when it passes check50 should you try to make it more complex by adding another function.

Here's bottles rewritten properly, though you will still have to integrate it properly in your code when you get there.

int bottles(int m);
{
    int bottles = /*FORMULA FOR BOTTLES*/;
    return bottles;
}

You must log in to answer this question.

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