Thread: Question About Grades??? (profoundly non-urgent)

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    Question Question About Grades??? (profoundly non-urgent)

    Hello, I m New In C Programing And I m Using "Turbo C 3.0" For Writing Programs. I Have Written A Program Which Source Code Is Below. The Program's Logic Is That, That It Takes Information Of 3 Students And I Had Used "Structure Array" In It. And I want that After Taking Marks Of Students It Will Print Percentage Which I Had Done But i Want "Grades" As Well To Be Print. My Source Is Below I Had Tried But On "grade=='A'","grade=='B'","grade=='C'", It Accours An error "Code Has No effect". Please Help Me Out And Paste Correct Source Code In answer Thanks!

    Code:
    #include<stdio.h>
    #include<string.h>
    
    struct students
    {
      char n[30];
      int m;
      int p;
      int u;
      int e;
    }std[3];
    
    void main()
    {
      int i=0;
      float per;
      char grade;
    
      clrscr();
      for(i=0;i<3;i++)
      {
        printf("\t\t:: Enter Information Of Student %d ::", i+1);
    
        printf("\nName: ");
        scanf("%s", std[i].n);
    
        printf("\nMaths: ");
        scanf("%d", &std[i].m);
    
        printf("\nPhysics: ");
        scanf("%d", &std[i].p);
    
        printf("\nUrdu: ");
        scanf("%d", &std[i].u);
    
        printf("\nEnglish: ");
        scanf("%d", &std[i].e);
      }
      printf("\n\t\t::.Percentage Of Students.::");
      for(i=0;i<3;i++)
      {
        per=(std[i].m+std[i].p+std[i].u+std[i].e)*100/400;
        printf("\nPercentage Of %s Is %.2f%", std[i].n, per);
      }
    
      printf("\n\n::.Grades Of Students.::");
      if(per>=70.00)
      {
        grade=='A';
      }
      if(per>=60.00)
      {
        grade=='B';
      }
        if(per>=50.00)
      {
        grade=='C';
      }
      for(i=0;i<3;i++)
      {
        printf("\nGrade Of %s Is %c",std[i].n, grade);
      }
      getch();
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    1) == does not mean "assign to".

    2) "A" is not a char. 'A' is a char.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    Thanks! But can You Give Me Correct Code ????

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    He just did. Do some work you lazy ....

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You assigned 0 to your variable i multiple times, use the same logic (and the same operator) to assign 'A' to your variable.

    On a sidenote: why are people from the indian subcontinent so obsessed with using software that is way older than they are? Turbo C is software stoneage, I've been using more recent compilers 15 years ago in school. There are many good and free compilers out there, if Turbo C is not an external requirement by your teacher, go grab a great free compiler from this millenium.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    Thumbs down

    Quote Originally Posted by kermit View Post
    He just did. Do some work you lazy ....
    Me NOt Lazy Dude ... I Didn't Understood Second Point .... And yeh ! If i Use grade='A' It Always Come "Grade C" why ?? Even Percentage is greater than 70 or 60 Please Help Me Out!!

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    It's your logic. Assume per is 80.

    Code:
    if(per>=70.00) // yes, 80 > 70
      {
        grade=='A'; // grade is set to A
      }
      if(per>=60.00) // yes, 80 > 60
      {
        grade=='B'; // grade is set to 'B'
      }
        if(per>=50.00) // yes, 80 > 50
      {
        grade=='C'; // grade is set to 'C'
      }
    You need to make sure you check for grades B downward only if it's not already determined to be an 'A'. Hint: use the "else" keyword.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Post your latest code.

    And drop the "I Write Like This" initial caps style.
    How To Ask Questions The Smart Way
    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.

  9. #9
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    Thumbs up

    Quote Originally Posted by nvoigt View Post
    It's your logic. Assume per is 80.

    Code:
    if(per>=70.00) // yes, 80 > 70
      {
        grade=='A'; // grade is set to A
      }
      if(per>=60.00) // yes, 80 > 60
      {
        grade=='B'; // grade is set to 'B'
      }
        if(per>=50.00) // yes, 80 > 50
      {
        grade=='C'; // grade is set to 'C'
      }
    You need to make sure you check for grades B downward only if it's not already determined to be an 'A'. Hint: use the "else" keyword.
    Thanks you So Much I Understand My Mistake! My Problem Is Solved!!!!

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Master Ali View Post
    Thanks you So Much I Understand My Mistake! My Problem Is Solved!!!!
    Well, except for that Flintstones compiler you're using....

    Give this a try...

    smorgasbordet - Pelles C


    It's free... it's fast and it's very well documented.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    5 years later on, and no improvement...
    Institutionalised obsolescence
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. question about ifstreams
    By Amyaayaa in forum C++ Programming
    Replies: 6
    Last Post: 05-27-2008, 03:48 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM