By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Expression syntax error in function main

P: 4
Hi and good day to all...I am new to the C language and whenever I tried to run the program I made, it won't because it says it has an "expression syntax error in function main"..what I don't get is that I know I had it done correctly and just to make sure if I was mistaken or not in writing my programs, I even copied some exapmles of programs in my book and and even in the internet...when I tried running these programs, they do not run too and says exactly the same error I've committed..please help!..
Feb 20 '07 #1
Share this Question
Share on Google+
7 Replies


RedSon
Expert 5K+
P: 5,000
A syntax error means that that code that you have written or copied into your environment was wrong or is missing some important part. If you copy and paste your code to this forum we can help you search for syntax errors. Syntax errors are the easiest errors to correct so it should be no trouble. Be sure to use "CODE" tags around your code when you copy and paste it.
Feb 20 '07 #2

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<string.h>
  3. #define p printf
  4. #define s scanf
  5. #define g gotoxy
  6.  
  7. main()
  8. {
  9.     int ctr,count;
  10.     char log[10],pass[10];
  11.     char ans, wrd[30], letter='a';
  12.     float Q1,Q2,Q3,gen_ave,mid,aten,agg,fQ1,fQ2,fQ3,fgen_ave,fa,fmid,faten,fagg,b,a,f;
  13.     int c,choice;
  14.     int gc,a1,a2,equal;
  15.  
  16.  
  17.     Q1=0;
  18.     Q2=0;
  19.     Q3=0;
  20.     mid=0;
  21.     aten=0;
  22.     fQ1=0;
  23.     fQ2=0;
  24.     fQ3=0;
  25.     fmid=0;
  26.     faten=0;
  27.  
  28.     clrscr();
  29.     p("Username: ");
  30.     g(1,2);
  31.     p("Enter your password: ");
  32.  
  33.     g(11,1);
  34.     s("%s",log);
  35.     c=strcmp(log,"mariano");
  36.  
  37.     g(22,2);
  38.     s("%s",pass);
  39.     c=strcmp(pass,"lenonmariano");
  40.  
  41.  
  42.     if(c==0)
  43.     {
  44.         clrscr();
  45.         g(30,2);
  46.         p("Main Menu");
  47.         g(30,5);
  48.         p("1. Computation");
  49.         g(30,6);
  50.         p("2. Grade Computation");
  51.         g(30,7);
  52.         p("3. String Manipulation");
  53.         g(30,8);
  54.         p("4. Vowel");
  55.         g(30,9);
  56.         p("5. Exit");
  57.         g(30,11);
  58.         p("Choose [1-5]: ");
  59.         s("%d",&choice);
  60.     }
  61.     else
  62.         p("Wrong Username or Password");
  63.  
  64.     if(choice==1)
  65.     {
  66.         clrscr();
  67.         g(35,2); p("Main Menu");
  68.         g(33,5); p("1. ADDITION");
  69.         g(33,6); p("2. SUBTRACT");
  70.         g(33,7); p("3. MULTIPLY");
  71.         g(33,8); p("4. DIVIDE");
  72.         g(33,9); p("5. QUIT");
  73.         g(28,11); p("Choose Computation [1-5]: ");
  74.         s("%d",&gc);
  75.     }
  76.     else if(choice==2)
  77.     {
  78.         clrscr();
  79.         g(5,3); p("Q1");
  80.         g(10,3); p("Q2");
  81.         g(15,3); p("Q3");
  82.         g(20,3); p("Midterm");
  83.         g(30,3); p("Attendance");
  84.         g(45,3); p("Over All Grade");
  85.  
  86.         g(5,4); s("%f",&Q1);
  87.         g(10,4); s("%f",&Q2);
  88.         g(15,4); s("%f",&Q3);
  89.  
  90.         gen_ave=(Q1+Q2+Q3)/3;
  91.  
  92.         g(20,4); s("%f",&mid);
  93.         g(30,4); s("%f",&aten);
  94.         g(45,4); agg=(gen_ave*.3)+(mid*.6)+(aten*.1);
  95.         p("%.2f",agg);
  96.         getch();
  97.  
  98.         clrscr();
  99.  
  100.         g(5,3); p("Q1");
  101.         g(10,3); p("Q2");
  102.         g(15,3); p("Q3");
  103.  
  104.         g(5,3); p("Q1");
  105.         g(10,3); p("Q2");
  106.         g(15,3); p("Q3");
  107.         g(20,3); p("Final Term");
  108.         g(30,3); p("Attendance");
  109.         g(45,3); p("Over All Grade");
  110.  
  111.         g(5,4); s("%f",&fQ1);
  112.         g(10,4); s("%f",&fQ2);
  113.         g(15,4); s("%f",&fQ3);
  114.  
  115.         fgen_ave=(fQ1+fQ2+fQ3)/3;
  116.  
  117.         g(20,4); s("%f",&fmid);
  118.         g(30,4); s("%f",&faten);
  119.  
  120.         g(45,4); fagg=(fmid*.6)+(faten*.1)+(fgen_ave*.3);
  121.         p("%.2f",fagg);
  122.  
  123.         getch();
  124.         clrscr();
  125.  
  126.         g(5,3); p("Final Grade");
  127.         b=agg*.40;
  128.         a=fagg*.60;
  129.  
  130.         g(5,4);
  131.         f=b+a;
  132.         p("%.2f",f);
  133.     }
  134.     else if(choice==3)
  135.     {
  136.         clrscr();
  137.         count=0;
  138.             g(22,8); p("Enter A String: ");
  139.             s("%s",&wrd);
  140.             g(22,9);
  141.                 for(ctr=0; (ctr(=strlen(wrd)-1); ctr++)
  142.                 {
  143.                     if(wrd[ctr]==letter)
  144.                     {
  145.                         count=count+1;
  146.                     }
  147.                 }
  148.         p("Your letter is: ");
  149.         p("%i",count);
  150.  
  151.     }
  152.     getch();
  153. }
  154.  
  155.  
email me if you see my error! <Removed>! help me!
Apr 2 '09 #3

10K+
P: 13,264
1.) You did not use the code tags suggested above.
2.) main must return an int. Read Ten Common Silly Mistakes
3.) Where did you declare clrscr which you are calling often? Perhaps you forgot to include conio.h (which is not available on all platforms and so should be avoided)
Apr 2 '09 #4

100+
P: 687
email me if you see my error
You confused angle bracket and parenthesis in the line pointed by compiler. Btw, you could have posted its number here so that I didn't copypaste your code and compile it for you.
Apr 2 '09 #5

P: 1
//Just try to execute now you will get answer...


#include<stdio.h>
#include<string.h>
#define p printf
#define s scanf
#define g gotoxy

void main()
{
int ctr,count;
char log[10],pass[10];
char ans, wrd[30], letter='a';
float Q1,Q2,Q3,gen_ave,mid,aten,agg,fQ1,fQ2,fQ3,fgen_ave ,fa,fmid,faten,fagg,b,a,f;
int c,choice;
int gc,a1,a2,equal;


Q1=0;
Q2=0;
Q3=0;
mid=0;
aten=0;
fQ1=0;
fQ2=0;
fQ3=0;
fmid=0;
faten=0;

clrscr();
p("Username: ");
g(1,2);
p("Enter your password: ");

g(11,1);
s("%s",log);
c=strcmp(log,"mariano");

g(22,2);
s("%s",pass);
c=strcmp(pass,"lenonmariano");


if(c==0)
{
clrscr();
g(30,2);
p("Main Menu");
g(30,5);
p("1. Computation");
g(30,6);
p("2. Grade Computation");
g(30,7);
p("3. String Manipulation");
g(30,8);
p("4. Vowel");
g(30,9);
p("5. Exit");
g(30,11);
p("Choose [1-5]: ");
s("%d",&choice);
}
else
p("Wrong Username or Password");

if(choice==1)
{
clrscr();
g(35,2); p("Main Menu");
g(33,5); p("1. ADDITION");
g(33,6); p("2. SUBTRACT");
g(33,7); p("3. MULTIPLY");
g(33,8); p("4. DIVIDE");
g(33,9); p("5. QUIT");
g(28,11); p("Choose Computation [1-5]: ");
s("%d",&gc);
}
else if(choice==2)
{
clrscr();
g(5,3); p("Q1");
g(10,3); p("Q2");
g(15,3); p("Q3");
g(20,3); p("Midterm");
g(30,3); p("Attendance");
g(45,3); p("Over All Grade");

g(5,4); s("%f",&Q1);
g(10,4); s("%f",&Q2);
g(15,4); s("%f",&Q3);

gen_ave=(Q1+Q2+Q3)/3;

g(20,4); s("%f",&mid);
g(30,4); s("%f",&aten);
g(45,4); agg=(gen_ave*.3)+(mid*.6)+(aten*.1);
p("%.2f",agg);
getch();

clrscr();

g(5,3); p("Q1");
g(10,3); p("Q2");
g(15,3); p("Q3");

g(5,3); p("Q1");
g(10,3); p("Q2");
g(15,3); p("Q3");
g(20,3); p("Final Term");
g(30,3); p("Attendance");
g(45,3); p("Over All Grade");

g(5,4); s("%f",&fQ1);
g(10,4); s("%f",&fQ2);
g(15,4); s("%f",&fQ3);

fgen_ave=(fQ1+fQ2+fQ3)/3;

g(20,4); s("%f",&fmid);
g(30,4); s("%f",&faten);

g(45,4); fagg=(fmid*.6)+(faten*.1)+(fgen_ave*.3);
p("%.2f",fagg);

getch();
clrscr();

g(5,3); p("Final Grade");
b=agg*.40;
a=fagg*.60;

g(5,4);
f=b+a;
p("%.2f",f);
}
else if(choice==3)
{
clrscr();
count=0;
g(22,8); p("Enter A String: ");
s("%s",&wrd);
g(22,9);
for(ctr=0;(ctr<=strlen(wrd)-1); ctr++)
{
if(wrd[ctr]==letter)
{
count=count+1;
}
}
p("Your letter is: ");
p("%i",count);

}
getch();
}
Aug 24 '12 #6

P: 1
Thank u so much... your answer helped me a lot.. thanx once again...
Feb 4 '13 #7

P: 1
#include<conio.h>
#include<stdio.h>
#include<string.h>
#define p printf
#define s scanf
#define g gotoxy

void main()
{
int ctr,count;
char log[10],pass[10];
char ans, wrd[30], letter='a';
float Q1,Q2,Q3,gen_ave,mid,aten,agg,fQ1,fQ2,fQ3,fgen_ave ,fa,fmid,faten,fagg,b,a,f;
int c,choice;
int gc,a1,a2,equal;


Q1=0;
Q2=0;
Q3=0;
mid=0;
aten=0;
fQ1=0;
fQ2=0;
fQ3=0;
fmid=0;
faten=0;

clrscr();
p("Username: ");
g(1,2);
p("Enter your password: ");

g(11,1);
s("%s",log);
c=strcmp(log,"mariano");

g(22,2);
s("%s",pass);
c=strcmp(pass,"lenonmariano");


if(c==0)
{
clrscr();
g(30,2);
p("Main Menu");
g(30,5);
p("1. Computation");
g(30,6);
p("2. Grade Computation");
g(30,7);
p("3. String Manipulation");
g(30,8);
p("4. Vowel");
g(30,9);
p("5. Exit");
g(30,11);
p("Choose [1-5]: ");
s("%d",&choice);
}
else
p("Wrong Username or Password");

if(choice==1)
{
clrscr();
g(35,2); p("Main Menu");
g(33,5); p("1. ADDITION");
g(33,6); p("2. SUBTRACT");
g(33,7); p("3. MULTIPLY");
g(33,8); p("4. DIVIDE");
g(33,9); p("5. QUIT");
g(28,11); p("Choose Computation [1-5]: ");
s("%d",&gc);
}
else if(choice==2)
{
clrscr();
g(5,3); p("Q1");
g(10,3); p("Q2");
g(15,3); p("Q3");
g(20,3); p("Midterm");
g(30,3); p("Attendance");
g(45,3); p("Over All Grade");

g(5,4); s("%f",&Q1);
g(10,4); s("%f",&Q2);
g(15,4); s("%f",&Q3);

gen_ave=(Q1+Q2+Q3)/3;

g(20,4); s("%f",&mid);
g(30,4); s("%f",&aten);
g(45,4); agg=(gen_ave*.3)+(mid*.6)+(aten*.1);
p("%.2f",agg);
getch();

clrscr();

g(5,3); p("Q1");
g(10,3); p("Q2");
g(15,3); p("Q3");

g(5,3); p("Q1");
g(10,3); p("Q2");
g(15,3); p("Q3");
g(20,3); p("Final Term");
g(30,3); p("Attendance");
g(45,3); p("Over All Grade");

g(5,4); s("%f",&fQ1);
g(10,4); s("%f",&fQ2);
g(15,4); s("%f",&fQ3);

fgen_ave=(fQ1+fQ2+fQ3)/3;

g(20,4); s("%f",&fmid);
g(30,4); s("%f",&faten);

g(45,4); fagg=(fmid*.6)+(faten*.1)+(fgen_ave*.3);
p("%.2f",fagg);

getch();
clrscr();

g(5,3); p("Final Grade");
b=agg*.40;
a=fagg*.60;

g(5,4);
f=b+a;
p("%.2f",f);
}
else if(choice==3)
{
clrscr();
count=0;
g(22,8); p("Enter A String: ");
s("%s",&wrd);
g(22,9);
for(ctr=0;ctr=(strlen(wrd)-1);++ctr)
{
if(wrd[ctr]==letter)
{
count=count+1;
}
}
p("Your letter is: ");
p("%i",count);

}
getch();
}
Apr 8 '16 #8

Post your reply

Sign in to post your reply or Sign up for a free account.