0

I am a novice regarding compilers. Can somebody explain to me what the following printed errors mean?

Since I was not sure whether I will be violating the Honor Code, I have not included my greedy.c program. If it is permitted to include my computer code, I can send it to any e-mail address.

I have included the check50 output below.

Ramaswami Sastry Vedam sastryv34@yahoo.com.au

The compiler errors printed by clang:

jharvard@appliance (~/Dropbox/pset1): make greedy
clang -ggdb3 -O0 -std=c99 -Wall -Werror    greedy.c  -lcs50 -lm -o greedy
greedy.c:4:1: error: type specifier missing, defaults to 'int'
  [-Werror,-Wimplicit-int]
main()
^~~~
greedy.c:11:7: error: implicit declaration of function 'If' is invalid in C99
  [-Werror,-Wimplicit-function-declaration]
  If  (change < 0);
  ^
greedy.c:18:9: error: expected expression
    else 
    ^
greedy.c:23:20: error: use of undeclared identifier 'change'
int i = round (change*100);
               ^
greedy.c:26:37: error: type specifier missing, defaults to 'int'
  [-Werror,-Wimplicit-int]
   int i = 0, n1=0, n2=0, n3=0; n=0 ;
                                ^
greedy.c:28:4: error: expected identifier or '('
{    
^
6 errors generated.
jharvard@appliance (~/Dropbox/pset1):

greedy.c exists
greedy.c compiles
input of 0.41 yields output of 4
input of 0.01 yields output of 1
input of 0.15 yields output of 2
input of 1.6 yields output of 7
input of 23 yields output of 92
input of 4.2 yields output of 18
rejects a negative input like -.1
rejects a non-numeric input of "foo"
rejects a non-numeric input of ""
1

Your check50 results that you posted don't tell us whether or not you passed the test (they should have a :) or a :( or a :| next to them).

Your compiler errors are pretty self-explanatory: each error tells you the exact line where the error occurs and tells you what is wrong.

main() is not how you start a program. You should be using int main(void)

If is not correct. In C, the capitalization of reserved words is important. Try using if instead.

else expected expression: the compiler is expecting an expression to follow your else statement. Recall this syntax:

if (this condition is met)
{
    //do this;
}
else
{
    //do this instead;
}

change is undeclared. Have you declared it previously?

int i = 0, n1=0, n2=0, n3=0; n=0 ; Notice the arrow pointing. If you are going to declare a lot of ints, you need to separate them by commas (,) Your last one is separated by a semicolon (;) so the compiler expects a new declaration.

expected identifier or '(' Hard to know what is the issue there, but most likely you have a left off some needed punctuation or have an extra semicolon when it's unnecessary.

3
  • The undeclared int might have been declared inside the brackets of a loop. – m_duran Jul 6 '14 at 3:57
  • Kareem has given some useful suggestions to one of my other questions on greedy.c and has pointed out a few syntax errors which I have corrected. – uma1966 Jul 6 '14 at 19:50
  • The undeclared int might have been declared inside the brackets of a loop --- No Uma1966 reply tothe comments by m-duran – uma1966 Jul 7 '14 at 21:28

You must log in to answer this question.

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