1

I've been working on greedy.c and received this error in terminal:

greedy.c:23:1: error: expected identifier or '('
if cents > 25
^

I thought it had something to do with the if...else statement I used but I'm not sure. Any help would be greatly appreciated.

2

Unlike other languages(like python), in c++, if statements are used in the form

if (test_condition)
{
     // do something here
}
else if (another_test_condition)
{
     // do something here
} 
else
{
     // do something here
}

You need to use brackets() there. Another thing to be noted is that you should have googled the problem before asking on SE, that would do the work.

7
  • Wasn't aware the whole academic honesty thing extended to asking for help with certain segments of your code but now I know, I guess. Thanks anyways.
    – SS'
    Aug 14 '14 at 3:25
  • No problem, The error was enough to tell about the problem, you need not to put the corresponding code.
    – sinister
    Aug 14 '14 at 3:27
  • No, you can ask for help in segments of your code, but don't display any such information that may be a spoiler to others. Try this and tell whether it worked.
    – sinister
    Aug 14 '14 at 3:29
  • Added the brackets and the same error appears.
    – SS'
    Aug 14 '14 at 3:32
  • read answer code carefully again. Take care that syntax matches exactly the one given. There's a mistake with using else and also with blocks. '(' should be replaced by '{'
    – sinister
    Aug 14 '14 at 3:37

You must log in to answer this question.

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