Main Cpp 5 Parse Error Before Token
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more syntax error before token about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users syntax error before ' ' token in c Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each syntax error before erlang other. Join them; it only takes a minute: Sign up Parse error in code: expected ' ; ' before ' { ' token — what is causing this? up vote 1 down vote favorite The error I'm getting is error: expected ' ; ' before ' { ' token I tried fixing the code by adding ; after if (thisisanumber==5) as well as after else (thisisanumber!=5). While this solves the first error it creates another error that says error: ' else ' without a previous ' if '. I'd really love to know what error I've made in writing the code, thanks. Here is my code: #include using namespace std; int main() { int thisisanumber; cout<<"Whats the Password?: "; cin>> thisisanumber; cin.ignore(); if (thisisanumber==5) { cout<<"You've discovered the password! Wow, you're a genious you should be proud./n"; } else (thisisanumber!=5) { cout<<"You've failed in knowing the password and therefore cannot enter, leave and do not come back. Goodbye!/n"; } cin.get(); } c++ share|improve this question edited May 22 '12 at 23:54 Gaffi 3,13162859 asked Jun 27 '11 at 23:56 C2shiningC 83 Well, for a start, you declared main as returning an int, but I don't see a return statement anywhere. –cgmb Jun 27 '11 at 23:59 3 @Slavik81 main implicitly returns 0 in C++. –Ismail Badawi Jun 28 '11 at 0:02 Which line does the error point to? Also, an FYI unrelated to your question, a newline is \n not /n –Loduwijk Jun 28 '11 at 0:02 As you're new here, I hope you informed yourself about the accept and up-vote features. –Christian Rau Jun 28 '11 at 0:02 add a comment| 3 Answers 3 active oldest votes up vote 3 down vote accepted You don't need another condition as there are only two cases - just use else { ... } and it will catch all cases in which thisisanumber==5 is false. The structure of an if statement is: if (condition) { ... } else if (another condition) { ... } // ... more conditions e
1 New Topic/Question Reply 11 Replies - 11321 Views - Last Post: 13 September 2007 - 08:14 AM Rate Topic: #1 siren128 New D.I.C Head Reputation: 0 Posts: 18 Joined: 13-April 07 error: parse error before '{' token Posted 13 September 2007 - 02:16 AM Sorry for the minor problem but I need help!! I need to hand in this program in a few hours but I can't seem to find the parce error!!! #include #include #include main() { int a; int num[3][3]; srand((unsigned)time(NULL)); a = rand() % (7 + http://stackoverflow.com/questions/6500245/parse-error-in-code-expected-before-token-what-is-causing-this 1); /* getting random numbers 0-7*/ switch(a){ case 0: /* if a=0 and so on*/ num[3][3]={{8, 1, 6}, {3, 5, 7}, {4, 9, 2}}; printf("%d", num[3][3]); break; case 1: num[3][3]={{4, 3, 8}, {9, 5, 1}, {2, 7, 6}}; printf("%d", num[3][3]); break; case 2: num[3][3]={{2, 9, 4}, {7, 5, 3}, {6, 1, 8}}; printf("%d", num[3][3]); break; case 3: num[3][3]={{6, 7, 2}, {1, 5, 9}, {8, http://www.dreamincode.net/forums/topic/33165-error-parse-error-before-token/ 3, 4}}; printf("%d", num[3][3]); break; case 4: num[3][3]={{6, 1, 8}, {7, 5, 3}, {2, 9, 4}}; printf("%d", num[3][3]); break; case 5: num[3][3]={{8, 3, 4}, {1, 5, 9}, {6, 7, 2}}; printf("%d", num[3][3]); break; case 6: num[3][3]={{4, 9, 2}, {3, 5, 7}, {8, 1, 6}}; printf("%d", num[3][3]); break; case 7: num[3][3]={{2, 7, 6}, {9, 5, 1}, {4, 3, 8}}; printf("%d", num[3][3]); break; } } i get this when i compile it Æ@DDK5LN1X ~ $ gcc 56.c 56.c: In function `main': 56.c:14: error: parse error before '{' token 56.c:18: error: parse error before '{' token 56.c:22: error: parse error before '{' token 56.c:26: error: parse error before '{' token 56.c:30: error: parse error before '{' token 56.c:34: error: parse error before '{' token 56.c:38: error: parse error before '{' token 56.c:42: error: parse error before '{' token sorry for such a newbie question and program All it is doing is randomly showing the possible answers to a 3x3 magic square according to the random number that is generated and inserted into int a. Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: error: parse error
Programming Boards C Programming Syntax Error Before ';' Token Getting started with C or C++ | C Tutorial | C++ Tutorial | C and http://cboard.cprogramming.com/c-programming/128408-syntax-error-before-;-token.html C++ FAQ | Get a compiler | Fixes for common problems Thread: Syntax Error Before ';' Token Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch http://web.mst.edu/~cpp/common/common_errors.html to Hybrid Mode Switch to Threaded Mode 07-11-2010 #1 subhadeepgayen View Profile View Forum Posts Registered User Join Date Jul 2010 Posts 9 Syntax Error Before ';' Token Hi, I'm learning C error before Basics, Here's my code : Code: // This program finds the monthly installment #include #include int main(void){ float P,Rpct,R,M; int N; printf("\nEnter: Principal, Rate%, No. of yrs.\n"); scanf("%f %f %i",&P,&Rpct,&N); R = Rpct/100; M = P*R*pow(1+R,N)/(12*(pow(1+R,N)-1); printf("\n$%1.2f,@%11.2f%% costs $%1.2f over %i years",P,Rpct,M,N); printf("\nPayments will total $%1.2f",12*M*N); return 0; } I get the following error in DEV C++ : http://lookpic.com/d2/i2/1655/KFnQys1y.gif Can anyone shed some light syntax error before on it?? 07-11-2010 #2 ssharish2005 View Profile View Forum Posts Registered User Join Date Sep 2005 Location Cambridge, UK Posts 1,729 You where missing closing braket at the end Code: M = P*R*pow(1+R,N)/(12*(pow(1+R,N)-1)); ssharish Life is like riding a bicycle. To keep your balance you must keep moving - Einstein 07-11-2010 #3 subhadeepgayen View Profile View Forum Posts Registered User Join Date Jul 2010 Posts 9 oops...so silly of me., thanks for ur time 07-11-2010 #4 Elysia View Profile View Forum Posts C++まいる!Cをこわせ! Join Date Oct 2007 Posts 24,482 Better variable names wouldn't be a bad idea, either. Originally Posted by Adak io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions. Originally Posted by Salem You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much. Outside of your DOS world, your header file is meaningless. 07-11-2010 #5 kermit View Profile View Forum Posts ... Join Date Jan 2003 Posts 1,530 Also: Code: printf("\nEnter: Principal, Rate%%, No. of yrs.\n"); 07-11-2010 #6 LordPc View P