OK, you are pretty close, just some little syntax errors.
When I try to compile your source code with clang I get the following errors, so let's solve them step by step:
test.c:11:26: error: expected ';' at end of declaration
int i = get_int()
^
;
You get that error because you forgot to insert a ;
at the
command, at line 11. Let's fix that and compile again.
Now the first error we get is:
test.c:13:11: error: use of undeclared identifier 'i'
while(i < 0)
^
That's because you declared the i
inside the curly braces, so when
your code gets outside the curly braces, i
is out of scope, and
the compiler tells you it's not declared. What you can do to solve
this, is move the declaration of i
before the while loop like so:
int i;
do
{
i = get_int();
}
while(i < 0)
Lest's fix that and compile again.
Now we get the following error:
test.c:14:17: error: expected ';' after do/while statement
while(i < 0)
^
;
As the compiler tells you, there should be a ;
after the do/while
statement like so:
int i;
do
{
i = get_int();
}
while(i < 0);
Fix and compile as always.
Now the first error we get is:
test.c:18:24: error: use of undeclared identifier 'minuets'; did you mean 'minutes'?
int gallons = (minuets * 1.5);
^~~~~~~
minutes
Ahhh. That's a simple misspelling on line 18 (line 17 in your
original code). That's easy to fix! Do it, and compile again!
Now we get a warning (that's better, they are still erroneous commands, but less severe, so let's fix this too).
test.c:21:33: warning: format specifies type 'double' but the argument has type 'int' [-Wformat]
printf("bottles: %f\n", bottles);
~~ ^~~~~~~
%d
You want to print the value of bottles
, which is an int
, but in
printf()
you say that you will print a float
, and it's confused.
So replace the %f
with %d
to specify that you want to print an
int
and not a float
. Fix and compile!
Now everything works! Hooray!!! Now the hard part, to make sure that your code does what it's supposed to do. I'll leave that to you. ;)
In the future, when you find yourself in similar situations, just read the error messages, from top to bottom, and try to fix them one by one, like we did together. I'm sure you will make it on your own next time!
Good luck and Happy Coding!