0

I see the following three Clang compiler errors when I run greedy.c:

jharvard@appliance (~/Dropbox/pset1): make greedy
clang -ggdb3 -O0 -std=c99 -Wall -Werror    greedy.c  -lcs50 -lm -o greedy
greedy.c:7:4: error: expected identifier or '('
   { 
   ^
greedy.c:26:13: error: initializer element is not a compile-time constant
    int i = round (change*100) ;
            ^~~~~~~~~~~~~~~~~~
greedy.c:31:4: error: expected identifier or '('
   {    
   ^
3 errors generated.
jharvard@appliance (~/Dropbox/pset1): 

I ran check50 test of the program.

There is a :! in front of all the items for testing in the problem specification. As far as I can tell this program appears to pass check50 test in spite of the remaining compiler errors.

Can somebody tell me what these compiler errors are and how to eliminate them?

Ramaswami Sastry Vedam

E mail address: sastryv34@yahoo.com.au

7
  • It's quite hard to help you without seeing your code, but that is not allowed here. Are you using reddit too? If so, feel free to send me a private message with a link to your code ( reddit.com/message/compose/?to=delipity ) and I'll help you debug it. Your errors seem to be punctuation-based. -Brenda. – curiouskiwi Jul 6 '14 at 7:13
  • possible duplicate of greedy.c program compiler errors – curiouskiwi Jul 6 '14 at 7:14
  • Message to Brenda-Curiouskiwi – uma1966 Jul 6 '14 at 20:25
  • Message to Brenda-curiouskiwi I tried to join reedit using the link provided by you but it would not permit me for some reason. Only some users are permitted. My E mail address is sastryv34@yahoo.com.au – uma1966 Jul 6 '14 at 20:27
  • Message to Brenda-curiouskiwi – uma1966 Jul 6 '14 at 20:27
1
 reedy.c:7:4: error: expected identifier or '('
   { 
   ^

This first error is telling you that it doesn't know why you are opening a curly brace there. Without the code, what's goin on?

greedy.c:26:13: error: initializer element is not a compile-time constant
    int i = round (change*100) ;
            ^~~~~~~~~~~~~~~~~~

This looks like it is probably getting confused with the round function. Since you are already multiplying change by 100 and setting that to an int, do you need to round, or will you get the proper value without it?

greedy.c:31:4: error: expected identifier or '('
   {    

Same as the first error. At this point, curly braces are mainly used for opening a loop.

1
  • ,Already answered. My solution haspassed check50 test and graded also. uma1966 – uma1966 – uma1966 Oct 18 '15 at 17:25
0

Without seeing your code, here are some guesses: Errors on lines 7 and 31 likely from missing {, (, or preceding line lacks ;. Error on line 26 could be due to declaring i as a global variable, if that's what you're doing declare it in the body.

1
  • Already answered. My solution haspassed check50 test and graded also. uma1966 – uma1966 Oct 18 '15 at 17:21

You must log in to answer this question.

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