0
for (int i = height - 1, i >= 0, i--)
{
    for (int n = 0, n < i, n++)
        ... 
    for (int j = 0, j < total, j++)

[EDIT: irrelevant code removed for Honor Code compliance.]

This is what it gives me when I try to run it through the compiler:

clang -ggdb3 -O0 -std=c11 -Wall -Werror    mario.c  -lcs50 -lm -o mario
mario.c:12:30: error: redefinition of 'i'
for (int i = height - 1, i >= 0, i--)
                         ^
mario.c:12:14: note: previous definition is here
for (int i = height - 1, i >= 0, i--)
         ^
mario.c:12:32: error: invalid '>=' at end of declaration; did you mean '='?
for (int i = height - 1, i >= 0, i--)
                           ^~
                           =
mario.c:12:38: error: redefinition of 'i'
for (int i = height - 1, i >= 0, i--)
                                 ^
mario.c:12:14: note: previous definition is here
for (int i = height - 1, i >= 0, i--)
         ^
mario.c:12:39: error: expected ';' in 'for' statement specifier
for (int i = height - 1, i >= 0, i--)
                                  ^
mario.c:12:41: error: expected expression
for (int i = height - 1, i >= 0, i--)
                                    ^
mario.c:14:25: error: redefinition of 'n'
    for (int n = 0, n < i, n++)
                    ^
mario.c:14:18: note: previous definition is here
    for (int n = 0, n < i, n++)
             ^
mario.c:14:27: error: expected ';' in 'for' statement specifier
    for (int n = 0, n < i, n++)
                      ^
mario.c:14:27: error: expected expression
mario.c:17:25: error: redefinition of 'j'
    for (int j = 0, j < total, j++)
                    ^
mario.c:17:18: note: previous definition is here
    for (int j = 0, j < total, j++)
             ^
mario.c:17:27: error: expected ';' in 'for' statement specifier
    for (int j = 0, j < total, j++)
                      ^
mario.c:17:27: error: expected expression
11 errors generated.
make: *** [mario] Error 1

Any ideas please?

0

Syntax errors. If you review the proper form of a for loop construct, you'd see that the three clauses are separated by semicolons, not commas.

for( init clause ; text clause ; increment clause)

By using commas, the compiler thinks you're trying to initialize multiple vars, and sees the same one, the i, twice, so it throws an error.

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

You must log in to answer this question.

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