Thread: c program on grades of a student

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    63

    c program on grades of a student

    hi
    i have tried to do this c program but i have checked alot of times but it is still giving me 3 errors, like unterminated string or character constant ,function call missing ,statement missing,so plz tell me what's wrong in it?
    it should print fail when the average marks 0f 5 subjects are between 0 to 39;third division when the average marks of a student are between 40 to 49;second division when 50 to 59;first division when 60 to 79;it should print honours when the average marks are between 80 to 100.
    so i did like this:


    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    float eng,maths,de,it,c,avmar;
    printf("enter the marks for english:");
    scanf("%f",&eng);
    printf("enter the marks for maths:");
    scanf("%f",&maths);
    printf("enter the marks for digital electronics:");
    scanf("%f",&de);
    printf("enter the marks for information technology:");
    scanf("%f",&it);
    printf("enter the marks for c:");
    scanf("%f",&c);
    avmar=(eng+maths+de+it+c)/5;
    printf("the average marks are=%f",avmar);
    if((avmar<39)&&(avmar>0))
    printf("fail");
    else if((avmar<49)&&(avmar>40))
    printf("third division");
    else if((avmar<59)&&(avmar>50))
    printf("second division");
    else if((avmar<79)&&(avmar>60))
    printf("first division");
    else ((avmar<100)&&(avmar>80))
    printf("honours");
    getch();
    }
    now what's wrong in it?
    the compiler is showing error in line 14 as unterminated string or character constant?what do we mean by that?
    and in line 15 an d 27....
    im completely puzzeled by this....
    guys plz help me out..........
    have i written the corrct program........?
    Last edited by galmca; 09-29-2004 at 01:16 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Having told you to read THIS
    http://cboard.cprogramming.com/showthread.php?t=25765
    before posting code, guess what - you didn't
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    One problem is that in your final printf() you forgot the opening quotation. Fixing this one mistake may get rid of all your errors, as I don't see anything else wrong, but I'm not perfect.
    Code:
    printf(honours");
    also, the code works with void main() but it's good standard practice to use int main(), as Salem's banner says.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Doesn't your compiler tell you what line number the problem is on? It's on line 17:
    printf("the average marks are="%f",avmar);
    Count the quotes...
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    63
    hi
    iam sorry to bother u again but the thing is that i have tried using that and it is again givingme 3 errrors in line 14 as unterminated string or character constant and in line 15 function call missing in line 27 as statement missing;
    what do i do......?
    i have checked that 10 times,,,,it seems correct to me but it is giving me thses 3 errors when i compile this code.........

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by galmca
    hi
    iam sorry to bother u again but the thing is that i have tried using that and it is again givingme 3 errrors in line 14 as unterminated string or character constant and in line 15 function call missing in line 27 as statement missing;
    what do i do......?
    i have checked that 10 times,,,,it seems correct to me but it is giving me thses 3 errors when i compile this code.........
    Here's a hint: If it says "missing semicolon in line 27" and line 27 has a semicolon ---- Look at line 26 (!)

    Regards,

    Dave

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    63
    iam waiting guys plz help me out!!!!!! i'll be reallly greatful to u.......im stuck in this program for a very long time.....even though it seems correct to me.....why is showing an error in line 14 as unterminated string or character constant ?what does it mean?and alos in line 15 and 27.......
    plz help me out.....

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by galmca
    iam waiting guys plz help me out!!!!!! i'll be reallly greatful to u.......im stuck in this program for a very long time.....even though it seems correct to me.....why is showing an error in line 14 as unterminated string or character constant ?what does it mean?and alos in line 15 and 27.......
    plz help me out.....
    The code at the top of this thread (edited by you about 20 minutes ago as I post this) has one compilation error: missing semicolon in line 27.

    I told you where to look.

    Did you look there?

    Regards,

    Dave
    Last edited by Dave Evans; 09-29-2004 at 01:39 PM.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    63
    i have looked everywhere but ican't find anything wrong anywhere..........
    every line i have looked into.......
    plz dave help me out........
    and also tell me why is it giving me an error in line 14 as unterminated string or character constant.....even though it is correct.....

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >i have looked everywhere but ican't find anything wrong anywhere
    Code:
       else if ((avmar<100)&&(avmar>80))
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by galmca
    i have looked everywhere but ican't find anything wrong anywhere..........
    every line i have looked into.......
    plz dave help me out........
    and also tell me why is it giving me an error in line 14 as unterminated string or character constant.....even though it is correct.....
    I don't get an error in line 14. Post the code again.

    [edit]
    Never mind; I'll do it
    [/edit]

    As for line 27 Here are a few lines around line 27:

    Code:
    else if((avmar<79)&&(avmar>60))
    printf("first division");
    else ((avmar<100)&&(avmar>80))
    printf("honours");
    This is line 26
    Code:
    else ((avmar<100)&&(avmar>80))
    You probably meant
    Code:
    else if ((avmar<100)&&(avmar>80))
    Now this is unnecessary logic, and line 26 could simply be
    Code:
    else
    The fact is, however, your program would be syntactically correct if line 26 had a semicolon.

    I sense your frustration (believe it or not --- I can feel your pain), and I know it's hard to see some types of errors when you keep looking at the same stuff for hours at a time.

    It would be easier (at least it is for me) if you would use indentation and some kind of line spacing to make the code more readable

    Next time you post code put code tags around it.


    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
      float eng, maths, de, it, c, avmar;
    
      printf("enter the marks for english: ");
      
      scanf("%f", &eng);
      printf("enter the marks for maths: ");
    
      scanf("%f", &maths);
      printf("enter the marks for digital electronics: ");
      
      scanf("%f", &de);
      printf("enter the marks for information technology: ");
    
      scanf("%f", &it);
      printf("enter the marks for c: ");
    
      scanf("%f", &c);
      avmar=(eng + maths + de + it + c) / 5;
    
      printf("the average marks are = %f", avmar);
    
      if((avmar < 39) && (avmar > 0))
        printf("fail");
      else if((avmar < 49) && (avmar > 40))
        printf("third division");
      else if((avmar < 59) && (avmar > 50))
        printf("second division");
      else if((avmar < 79) && (avmar > 60))
        printf("first division");
      else
        printf("honours");
      
      getch();
    }
    Note there are a couple of bugs that you might not uncover by testing, so I'll give you a hint there also:

    Enter 50 for all of the grades and see how they are classified


    Regards,

    Dave
    Last edited by Dave Evans; 09-29-2004 at 02:16 PM.

  12. #12
    Registered User
    Join Date
    Sep 2004
    Posts
    63
    thank u dave ...i really am very gr8ful to u that u have taken that much amount of time for me....actually to be honest with u....it is still giving me 2 errors in line 14 and 15 right now....but the good news is that atleast the error in line 26 doesn't exist anymore.....

  13. #13
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by galmca
    thank u dave ...i really am very gr8ful to u that u have taken that much amount of time for me....actually to be honest with u....it is still giving me 2 errors in line 14 and 15 right now....but the good news is that atleast the error in line 26 doesn't exist anymore.....
    Copy-paste from my post. How many errors do you get? I get none.

    Regards,

    Dave

  14. #14
    Registered User
    Join Date
    Sep 2004
    Posts
    63
    hi dave
    iam really happy to announce that my program is working "properly" now.
    absolutely fine....without any errors......
    thx alot friend.....
    thx .....
    take care....

  15. #15
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by galmca
    hi dave
    iam really happy to announce that my program is working "properly" now.
    absolutely fine....without any errors......
    thx alot friend.....
    thx .....
    take care....
    OK! Now it compiles OK and executes withoug burning the house down.

    Don't forget to test it with the data that I suggested:

    All grades 50
    All grades 60
    All grades 70

    You require a minor change in some of the if statememts to make it give the right answers for all possible inputs.

    Good luck,

    Dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need the code of few programs in c++.plzzzzz help...plzzz
    By NAVINKR20 in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2009, 09:13 AM
  2. My program unexpectedly quits
    By Unclejunebug in forum C Programming
    Replies: 13
    Last Post: 04-05-2009, 10:30 AM
  3. Replies: 2
    Last Post: 02-08-2009, 09:26 PM
  4. How to complete program. Any probs now?
    By stehigs321 in forum C Programming
    Replies: 7
    Last Post: 11-19-2003, 04:03 PM
  5. Grades program has me lost
    By adrea in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2002, 08:35 PM