• C

C Program Problem

I keep on getting many error messages that I am missing some ")", but I have checked over and over again, and cannot find my error!   Here is the program, although I am not sure if it will come out properly in this area...(Sorry for the length!)


/* Sara Bissonnette */



#include <stdio.h>

#define MAXGRADE 100

#define SENTINEL 999



void instructions(void);
int getgrades(void);
void graph(int, int, int, int, int, int);


int main(void)

        {
      int A, B, C, D, F, Invalid;
      
        instructions();
        getgrades();
        graph(A, B, C, D, F, Invalid);
        }

void instructions(void)

        {
        printf("\n\n\nThis program will form a bar chart from a ");
        printf("sequence of grades.\n\n");
        }

int getgrades(void)

        {
      int A, B, C, D, F, Invalid, grade;

      A=0; B=0; C=0; D=0; F=0; Invalid=0;

        printf("Please enter a grade between 0 and %d, rounding " MAXGRADE);
        printf(" to the nearest integer.\nEnter %d when done:" SENTINEL);
      scanf("%d", &grade);

      while(((scanf("%d", grade)!=1)||(grade<0)||(grade>100))&&(grade!=SENTINEL))
            {
            Invalid ++;
            printf("That is not a valid grade.\n\n\n\nPlease reenter:");
            scanf("%d", &grade);
            }
      

      while (grade!=SENTINEL)
            {
            if (grade>=90) A++;
            else if (grade>=80) B++;
            else if (grade>=70) C++;
            else if (grade>=60) D++;
            else F++;
            }

      return(A, B, C, D, F, Invalid);

      }



void graph(int A, int B, int C, int D, int F, int Invalid);
      
      {
      printf("The following table corresponds to data containing ");
      printf("%d A's, %d B's, %d C's, %d D's, ", A, B, C, D);
      printf("%d F's and %d invalid grades.\n\n\n\n", F, Invalid);

      printf("A's: ");
      while (A!=0)
            {
            printf("X");
            A--;
            }

      printf("\n\nB's: ");
      while (B!=0)
            {
            printf("X");
            B--;
            }

      printf("\n\nC's: ");
      while (C!=0)
            {
            printf("X");
            C--;
            }

      printf("\n\nD's: ");
      while (D!=0)
            {
            printf("X");
            D--;
            }

      printf("\n\nF's: ");
      while (F!=0)
            {
            printf("X");
            F--;
            }
      printf("\n\n\n\n");

      }

SaraBizAsked:
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.

GleasonGuyCommented:
Take out the semi-colon after your declaration of graph()

void graph(int A, int B, int C, int D, int F, int Invalid);

should be

void graph(int A, int B, int C, int D, int F, int Invalid)

Hope that helps.
0
gindeCommented:
Here you go....
Try this

/* Sara Bissonnette */



#include <stdio.h>

#define MAXGRADE 100

#define SENTINEL 999



void instructions(void);
int getgrades(void);
void graph(int, int, int, int, int, int);


int main(void)

        {
      int A, B, C, D, F, Invalid;

        instructions();
        getgrades();
        graph(A, B, C, D, F, Invalid);
        }

void instructions(void)

        {
        printf("\n\n\nThis program will form a bar chart from a ");
        printf("sequence of grades.\n\n");
        }

int getgrades(void)

        {
int A, B, C, D, F, Invalid, grade;

A=0; B=0; C=0; D=0; F=0; Invalid=0;

        printf("Please enter a grade between 0 and %d, rounding ", MAXGRADE);
        printf(" to the nearest integer.\nEnter %d when done:", SENTINEL);
scanf("%d", &grade);

while(((scanf("%d", grade)!=1)||(grade<0)||(grade>100))&&(grade!=SENTINEL))
{
Invalid ++;
printf("That is not a valid grade.\n\n\n\nPlease reenter:");
scanf("%d", &grade);
}


while (grade!=SENTINEL)
{
if (grade>=90) A++;
else if (grade>=80) B++;
else if (grade>=70) C++;
else if (grade>=60) D++;
else F++;
}

return(A, B, C, D, F, Invalid);

}



void graph(int A, int B, int C, int D, int F, int Invalid)

{
printf("The following table corresponds to data containing ");
printf("%d A's, %d B's, %d C's, %d D's, ", A, B, C, D);
printf("%d F's and %d invalid grades.\n\n\n\n", F, Invalid);

printf("A's: ");
while (A!=0)
{
printf("X");
A--;
}

printf("\n\nB's: ");
while (B!=0)
{
printf("X");
B--;
}

printf("\n\nC's: ");
while (C!=0)
{
printf("X");
C--;
}

printf("\n\nD's: ");
while (D!=0)
{
printf("X");
D--;
}

printf("\n\nF's: ");
while (F!=0)
{
printf("X");
F--;
}
printf("\n\n\n\n");

}

0
rgoughCommented:
The printf's at the top of getgrades() are missing commas between the format string and the variables.  Also the declaration of the function graph() has a semi-colon at the end that shouldn't be there.
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

gindeCommented:
As GleasonGuy said, take out ; from graph
and also put commas "," in printf statement. Those are the  difference in code I provided above and yours.
0
GleasonGuyCommented:
rgough, With the new system here, you should post answers as comments. If the poster feels that your comment best addresses their question, then they can give you the points directly.

My initial answer addresses SaraBiz's error and ginde's comment (in long fashion) addresses both of her errors.

I saw the comma problem too, but thought SaraBiz could use a little extra time with the compiler ;-)

No big deal. We were all responding to the question at the same time.
0
DunbujeCommented:

while(((scanf("%d", grade)!=1)||(grade<0)||(grade>100))&&(grade!=SENTINEL))
In the above you could have written it the as:
while(((scanf("%d", &grade)!=1)||(grade<0)||(grade>100))&&(grade!=SENTINEL))
..

0
DunbujeCommented:

while(((scanf("%d", grade)!=1)||(grade<0)||(grade>100))&&(grade!=SENTINEL))
In the above, you could have written it as:
while(((scanf("%d", &grade)!=1)||(grade<0)||(grade>100))&&(grade!=SENTINEL))
Well that could help if any body else didn't comment on it.

Thank you.

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.