• C

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 : ')'
cbrookhartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

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
deightonprogCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.