[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

syntax error

I have written this program, however, I have not been able to get it to run. I actuall compiled this program in two different steps. I added a line to clear the buffer and then I compiled the program. The program worked the way it was supposed to. I deleted the files, and added the two print statements and received two syntax error messages. I don't see where I am missing a ')'. Have I put something in the wrong place? Also, I wanted to get an average for the scores, but I couldn't get that to work either. Below is the code and error messsages.

int main (void)
{
      int score[10];
      char name[10][15];
      int sub;
      int hisub = 0;
      int lowsub = 0;
      int total = 0;
/*int average = 0; ?*/
      for (sub = 0; sub<10; sub++)
      {
            printf("Enter Name: ");
            fflush (stdin);
            gets (name[sub]);
            printf("Please enter score for %s ", name[sub]);
            scanf("%d", &score[sub]);
            total=total+score[sub];
            if (score[sub]<score[lowsub])
                  lowsub=sub;
            if (score[sub]>score[hisub])
                  hisub=sub;
/*average=total/10;?*/
      }
      printf("Lowest score is %d received by %s\n",score[lowsub],name[lowsub]);
      printf("Highest score is %d received by %s\n"score[hisub],name[hisub]);
      return 0;
}

a:\scores.c(30) : error C2146: syntax error : missing ')' before identifier 'score'
a:\scores.c(30) : error C2059: syntax error : ')'
0
cbrookhart
Asked:
cbrookhart
1 Solution
 
BudVVeezerCommented:
printf("Highest score is %d received by %s\n"score[hisub],name[hisub]);

In there, right after the final ", you are missing a comma. ','

~Aaron
0
 
BudVVeezerCommented:
that SHOULD take care of the problem for you, if not, lemme know!

~Aaron

ps~ commas and semi colans KILL you every time!  ;-)
0
 
akalmaniCommented:
Hi !!
   The last printf dosen't have a comma before the array score check it and if have written a single printf in a continous 2 line i.e as u have shown, the printf does'nt provide by itself the '\n' character so write it in a single line
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
BudVVeezerCommented:
Whoa, you lost me on the last part of your comment.  I understand the part about the comma, well duh.  =P  But, other than the missing comma, the printf's look inorder and will work.

~Aaron
0
 
cbrookhartAuthor Commented:
I've fixed the missing comma. Is the coding for average correct?
0
 
BudVVeezerCommented:
As long as you have a valid value in every score[], ie there has to be 10 scores in order for it to work.  But then yeah, it'll work

~Aaron
0
 
cbrookhartAuthor Commented:
How do I keep the average from being printed as 6684216? I tried compiling with float average but that gives a warning about possible loss of data.
0
 
deightonCommented:
int main (void)
                      {
                      int score[10];
                      char name[10][15];
                      int sub;
                      int hisub = 0;
                      int lowsub = 0;
                      int total = 0;
                      /*int average = 0; ?*/
                      for (sub = 0; sub<10; sub++)
                      {
                      printf("Enter Name: ");
                      fflush (stdin);
                      gets (name[sub]);
                      printf("Please enter score for %s ", name[sub]);
                      scanf("%d", &score[sub]);
                      total=total+score[sub];
                      if (score[sub]<score[lowsub])
                      lowsub=sub;
                      if (score[sub]>score[hisub])
                      hisub=sub;
                      /*average=total/10;?*/
                      }
               printf("average = %f",(float) average / --sub);
0
 
BudVVeezerCommented:
comment to make here...

printf("average = %f",(float) average / --sub);

You forgot that average was commented out in the declarations..so there is no 'average' variable.  You will want to change that to 'total' because that is the variable you are using.  I don't understand why you are using score[sub] when all you are looking for is the average.  You don't need an array, just a single variable.  You can check that variabe against the highs and lows just like you are doing..and save on space.  Same thing with the name.  Just a thought!

~Aaron
0
 
cbrookhartAuthor Commented:
I wasn't sure how to write the average so that's why I left the comment indicators. I removed them before compiling. I added the score numbers up and the average is 82. This was the first output for average: 6684216
The second output is 9.111111. The first output was using %d and the second output is using %f.
0
 
BudVVeezerCommented:
Ah, yeah, that tends to do it!  =)

~Aaron
0
 
cbrookhartAuthor Commented:
So, what do I need to do to have the output be 82. I know that the compiler by default uses six decimal places. I could use %.0f, but then the output would be 9

0
 
ozoCommented:
Don't divide the 82 by 9
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now