error expected before else

Want to improve this question? Update the question so it’s on-topic for Stack Overflow.

Closed 5 years ago .

I get these errors when I compile my code.

But I do not understand why. I checked all the bracing many times.

3 Answers 3

The error is in:

Remove the trailing ;

if(check(infix[i])); : remove the ; at the end.

Your code is like writing:

It’s a good practice to have < even if you have only one line under the statement.
Doing that might help you to reveal possible problems, like this ; you have there.

Another note, use && for clarity instead of nested if s..

Not the answer you’re looking for? Browse other questions tagged c compiler-errors or ask your own question.

Hot Network Questions

site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2019.11.15.35459

Thread Tools
Search Thread
Display
  • Linear Mode
  • Switch to Hybrid Mode
  • Switch to Threaded Mode

error: expected ‘(‘ before ‘else’

Hello

I am trying to write a program that decrypts a string that the user enters with the caesar cypher.

I am pretty sure the rest of my program is correct but I am getting this error: error: Expected ‘(‘ before ‘else’ for line 37 (if else (plain [i] > 96 && plain[i] 04:09 PM .

You need to change «if else» to «else if».

Wow I knew it was something stupid

Thanks haha, I have been tearing my hair out over this.

Wow I knew it was something stupid

Thanks haha, I have been tearing my hair out over this.

Actually the correct grammar there would be . else if .

Actually now I am getting an error for the line:
else if (plain [i] == » «)
printf(» «);

It should be pretty obvious what I want to do. How do I do it?? haha

You can’t compare strings with ==, you need to use strcmp. If you want to check a single char, use single quotes: ‘ ‘.

How can I use strcmp() with plain[i] and ‘ ‘?

I’m guessing I would check if it == 0?

Thanks a lot for the really fast responses by the way

Sorry, I should have been more clear. It looks like you want to check against a single space character. Single quotes ‘ ‘ are for single characters, double quotes » » are for strings. You can compare single characters with ==, so you want if (plain[i] == ‘ ‘). If you wanted to compare strings, you would need if (strcmp(some_string, «foobar») == 0). Hope that makes a little more sense.

Thank you so much everyone I finally got it to work!

I’m creating a program that, after selecting an item from a list (time increments), it tells you how many hours, weeks, etc. old you are. It tells me, though, that it expects a primary expression before «else». What am I doing wrong?

using namespace std;

double weeks (double x) <

double y = (52 * x);

double days(double x) <

double y = (365.25 * y);

double hours(double x) <

double y = (365.25 * 24 * x);

7 Answers

both of your IF statements are missing curly brackets.

Expected Primary-expression Before

This Site Might Help You.

C++ error (expected primary expression before «else»)?

I’m creating a program that, after selecting an item from a list (time increments), it tells you how many hours, weeks, etc. old you are. It tells me, though, that it expects a primary expression before «else». What am I doing wrong?

For the best answers, search on this site https://shorturl.im/avknv

The target of an if is always a single statement, BUT that statement can be a compound statement — one enclosed in <-->brackets. In other words, this: else if (prop_shift) cout >percent; scaled_score=(percent*orig_score) + orig_score; cout >percent; scaled_score=(percent*orig_score) + orig_score; cout

Оцените статью