1

I am making a C program that is a simple calculator without a GUI, called "Quical". (Check out the code on Github). I am somewhat new to C, and so I am making some syntax errors. One of the errors is this:

expected declaration or statement at end of input

Another one of the errors that comes up is this:

else without a previous if

Here is my code.

Hopefully, this can shed some light as to why I am getting these syntax errors. Any help would be much appreciated.

Zong
  • 6,160
  • 5
  • 32
  • 46
javathunderman
  • 1,074
  • 2
  • 13
  • 31
  • Not sure if it's an artifact from posting code on github, but you have quite a few statements after 'if' and 'else' that are not in blocks nor indented which I assume you don't want. – Inisheer Mar 08 '14 at 02:18
  • SO is a place for posting code, not links to code. The actual relevant code should be directly in your question--for multiple reasons. – nhgrif Mar 08 '14 at 02:21
  • It may be a little messy. If you want to clean it up, I heartily request you file a pull request to the repo. – javathunderman Mar 08 '14 at 02:21
  • @nhgrif: I tried to do that, but the whole thing got messed up with formatting. It just seemed easier, and I already have the code there anyway. – javathunderman Mar 08 '14 at 02:22
  • Lines 84 and 117 there are else's lost(without if's). Why don't you use switch statement? – Evelin Amorim Mar 08 '14 at 02:31

1 Answers1

1

Your braces don't match. You have something like

main()
{
   some statement
   {
   }

   another
   {
   }


and it ends.

It is saying it wants a statement here. Try that and see what the next error is.

kmort
  • 2,848
  • 2
  • 32
  • 54
  • Any chance you could push a pull request on the repository itself? – javathunderman Mar 08 '14 at 02:28
  • I could do it for you, but how would you learn? :-) What IDE are you using, if any? Most of them should be able to Beautify or format your code for you so it's easy to see unbalanced curly braces. – kmort Mar 08 '14 at 02:29
  • :) I am using Eclipse. Oddly, there is a "quick fix" feature, but it doesn't seem to correct the code automatically. – javathunderman Mar 08 '14 at 02:30
  • @JavaThunderMan See this link for how to automatically format it. This will help you see where braces are unbalanced. http://stackoverflow.com/questions/15655126/how-to-auto-format-code-in-eclipse – kmort Mar 08 '14 at 02:31
  • Will try that link... – javathunderman Mar 08 '14 at 17:15