0

I have been attempting to create the water code for pset1, but when I try to compile, it sends me an error message. I am wondering if my code contains a syntax error. Here it is:

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

int a;

int main(void);
{
    scanf("a\n");
}

{
    printf("a*12\n");
}

Thanks for the help in advance.

0

You might think water is complicated.

I did too when I did it, but I realized it's as simple as

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

Don't forget and

Note : The CS50 policy said you can show your code to others but they can't show their code to you if they have the problem.

| improve this answer | |
  • Is my answer helpful? – WhipStreak23 Dec 12 '17 at 14:52
-1

You should use %d as the type specifier since you are dealing with decimal integers:

scanf("%d", &a)
printf("%d\n", 12*a)
| improve this answer | |
  • That doesn't work, I still get an error. – Elephant1123 Apr 26 '16 at 14:46
  • Sorry, my bad, I left out the "&", see edit above. Also, that's not your only error. If this is the entirety of your code, then you left out a return value. You also want to enclose everything below main to the return value in "{" and "}". – ronga Apr 27 '16 at 3:34
  • wait, what, exactly? Can you explain that in a way that make more sense? and what is a return value? – Elephant1123 Apr 27 '16 at 14:49
  • It would probably help if you viewed the lectures again. You need to enclose the body of the code after main in curly braces "{ }". As it is, you have 2 sets of them, you only need 1. Assuming you correct the scanf and printf syntax as suggested, you also need to add a return value line. Typically it is 0 (return 0), unless there is an error, in which case you can use some other number. – ronga Apr 28 '16 at 5:02
  • My code is now the following, and it still isn't working: – Elephant1123 Apr 28 '16 at 14:50

You must log in to answer this question.

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