0

I don't think I have using the whole "%" and "int" thing properly? I'm also not sure how to remove the formatting from the error message in this forum post, sorry.

Here is my code:

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

int main (void)  
{
    int LengthOfShower;

    do
    {
        // Prompt user for length of their shower (minutes)
        printf("How many minutes do your showers last?");

        LengthOfShower = GetInt();
    }
    while (LengthOfShower < 0);

    // Calculate how many bottle equals their length of shower
    int NumberOfBottles = LengthOfShower * 12;

    // Print the number of bottles they use in their shower
    printf("Bottles: %f, NumberOfBottles");
}

When I try to compile it I get these two error messages:

 $ make water

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    water.c  -lcs50 -lm -o water

water.c:20:23: error: more '%' conversions than data arguments
      [-Werror,-Wformat]
    printf("Bottles: %f, NumberOfBottles");
                     ~^   
water.c:17:9: error: unused variable 'NumberOfBottles'
      [-Werror,-Wunused-variable]
    int NumberOfBottles = LengthOfShower * 12;
        ^   
2 errors generated.

make: *** [water] Error 1
1
 %f

is a format specifier wrong for an integer, the right thing would be %i, or %d. Since NumberOfBottles is an integer, the variable is unused, hence the second error, but in this case will be corrected when we use the correct formatting for an integer.

EDIT: The most obvious things are we overlook, excuse my cluelessness. The error persists because we must "plug" with the variable that we want to print:

printf("Bottles: %d", NumberOfBottles);

the quotes are to blame

3
  • Thank you for fixing my question format! I tried switching %f to other letters including %i and %d, but it still give me the same error? I feel like I'm over looking something obvious. Aug 1 '16 at 19:18
  • You can read my edit, I'm sorry
    – MARS
    Aug 1 '16 at 19:39
  • Oh wow that makes sense! Thank you! Aug 1 '16 at 20:03
0

my suggestion would be this: printf("Bottles: %f", NumberOfBottles);

the issue has nothing to do with if you use %f, %i or etc. it has something to doo with syntax of the code.the error message says more conversions than data argument simply because of your placement of double quote

fixing the other problem is easy just assign variable

 int NumberOfBottles();
NumberOfBottles = LengthOfShower * 12;
printf("Bottles: %f" , NumberOfBottles);

You must log in to answer this question.

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