Thread: A Little Help

  1. #16
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    So I rewrote the program
    Code:
    #include <stdio.h>
    #include <math.h>
    
      int main(int argc, char* argv[]);
    { 
      int a1, a2, a3, a4, a5, m6, m7, f8;
      float Total;
      char Grade;
      printf("Enter Grades: \n");
       scanf( "%d%d%d%d%d%d%d%d", &a1, &a2,&a3,&a4,&a5, &m6, &m7,&f8);
      Total=a1+a2+a3+a4+a5+m6+m7+f8;
      if a1<=4 || a2<=4 || a3<=4 || a4<=4 || a5<=4 || m6<=4 || m7<=4 || f8<=4;
       { 
    Grade='F';
       }
      if a1<=6 && a2<=6 && a3<=6 && a4<=6 && a5<=6 && m6<=6 && m7<=6 && f8<=6 && Total>48;
       { 
    Grade='C';
       }
      if a1<=8 && a2<=8 && a3<=8 && a4<=8 && a5<=8 && m6<=8 && m7<=8 && f8<=8 Total>58;
       { 
    Grade='B';
       }
      if Total > 64;
       {
      Grade='A';
       }
    printf("\na1=%d, a2=%d, a3=%d, a4=%d, a5=%d, m6=%d, m7=%d, f8=%d\n", a1, a2, a3, a4, a5, m6, m7, f8);
    printf("\nTotal=%f,Grade is %c\n", Total, Grade);
    
      return 0;
    }
    Code:
    But it's giving me an error PA12.c:5:1: error: expected identifier or ‘(’ before ‘{’ token
    I cant find it...
    Last edited by jlovejoy; 02-13-2012 at 04:13 PM.

  2. #17
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    Sorry forgot to indent

  3. #18
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Enclose your if conditional statement in parentheses. And (line 20) don't forget to put separators between them.

  4. #19
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    Ok so I finish the first program I now need a little help fixing it so it does what number 2 says...

    Here is the finished code...

    Code:
    #include <stdio.h>
    #include <math.h>
    
     int main(int argc, char* argv[])
    { 
     int a1, a2, a3, a4, a5, m6, m7, f8;
     float Total, a, m, f, fg;
      char Grade;
     printf("Enter Grades: \n");
       scanf("%d%d%d%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5, &m6, &m7, &f8);
      Total=a1+a2+a3+a4+a5+m6+m7+f8;
    
     a = (a1+a2+a3+a4+a5)*.07;
     m = (m6+m7)*.2;
     f = (f8)*.25;
     fg = a+m+f;
    
    
     if (a1<=4 || a2<=4 || a3<=4 || a4<=4 || a5<=4 || m6<=4 || m7<=4 || f8<=4)
       { 
     Grade='F';
       }
     if (Total>=48)
       { 
     Grade='C';
       }
     if (Total>=64)
       { 
     Grade='B';
       }
     if (Total >=70)
       {
     Grade='A';
       }
     
    printf("\na1=%d, a2=%d, a3=%d, a4=%d, a5=%d, m6=%d, m7=%d, f8=%d\n", a1, a2, a3, a4, a5, m6, m7, f8);
     printf("\nTotal=%f,Grade is %c\n", fg, Grade);
    
     return 0;
    }

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So what equation are you trying to solve here? What f8 value, will give a student a grade point total (fg), that is less than 48 (F)? What f8 will give an fg >=48 and less than 64? What about >=64 and less than 70?

    You could find it via the arithmetic, or (much less efficient and less desirable), find it by looping through values, stepping them up until they reach the desired answer. It's a puke algorithm this second way, but it's there.

    Concentrating on the first way, what would be the equation?

Popular pages Recent additions subscribe to a feed