• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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");

      }

0
SaraBiz
Asked:
SaraBiz
  • 2
  • 2
  • 2
  • +1
1 Solution
 
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
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now