I've tried many variations, listened to the lecture twice, the walkthrough many times and the YouTube videos on C but still can't get the seemingly simple water problem to work. Please explain where I'm going wrong.

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

int main(void)

 int Minutes = get_int();
 printf("Minutes is /n");
    int Bottles = Minutes * 12;

You should review the class material and google references for printf. Specifically, to print the value of a variable, you need a place marker in the print format string and the var name in the printf statement. Example:

int count = get_int("Give me an integer: ");
printf("You said %i \n", count);

Note the placeholder %i that says 'put the integer here.' The first var after the comma which follows the string must be that int. If multiple vars are to be printed, they have to be in the same order as their corresponding placeholders appear in the string.

As an aside, based on your questions so far, you would benefit greatly for studying syntax of various commands and function calls very carefully until you get used to programming in C. You may have experience in other languages, but the syntax of one language often doesn't carry over to a different one.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • I'm a total novice and not inadvertently using another programming language. I did try reviewing C commands and I also tried using the %i placeholder. I tried it with separate printf lines for each variable and as a single line with the placeholders in proper order after the "," without success. But, thanks for trying to point me in the right direction.
    – comuter
    Oct 28 '17 at 0:38
  • Here is one of the many iterations I've tried. This one used the "%i" but it gives me an error "data argument not used by format string". I'll keep researching it.
    – comuter
    Oct 28 '17 at 0:47

Thanks for the suggestions. Typos were a large part of the problem but this worked:



int main(void)

{ printf("Minutes of showertime:"); int Minutes = get_int(); int Bottles = Minutes * 12; printf("Minutes:%i \n", Minutes); printf("Bottles:%i \n", Bottles); }

You must log in to answer this question.

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