Thread: Prob with my GPA calculator

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    46

    Prob with my GPA calculator

    The program ends after I input the last mark(the programming applications mark)I dunno y.

    Code:
    #include<stdio.h>
    #include<math.h>
    int
    main()
    {
          double esp,math,circuits,solid,art,pc,total,gpa;
        
          printf("\nEnter ESP3 mark :");
          scanf("%lf", &esp);
          printf("\nEnter Maths3 mark :");
          scanf("%lf", &math);
          printf("\nEnter Electrical Circuits 1 mark :");
          scanf("%lf", &circuits);
          printf("\nEnter Solid State Electronics mark :");
          scanf("%lf", &solid);
          printf("\nEnter Programming Applications mark :");
          scanf("%lf", &pc);
          
          if(esp>=90)
          esp=3*4.00;
          else
          if(90>esp>=85)
          esp=3*3.66;
          else
          if(85>esp>=80)
          esp=3*3.33;
          else
          if(80>esp>=75)
          esp=3*3.00;
          else 
          if(75>esp>=70)
          esp=3*2.66;
          else
          if(70>esp>=65)
          esp=3*2.33;
          else
          if(65>esp>=60)
          esp=3*2.00;
          else
          if(60>esp>=55)
          esp=3*1.66;
          else
          if(55>esp>=53)
          esp=3*1.33;
          else
          if(53>esp>=50)
          esp=3*1.00;
          else
          esp=3*0;
          
          
          
          if(math>=90)
          math=3*4.00;
          else
          if(90>math>=85)
          math=3*3.66;
          else
          if(85>math>=80)
          math=3*3.33;
          else
          if(80>math>=75)
          math=3*3.00;
          else 
          if(75>math>=70)
          math=3*2.66;
          else
          if(70>math>=65)
          math=3*2.33;
          else
          if(65>math>=60)
          math=3*2.00;
          else
          if(60>math>=55)
          math=3*1.66;
          else
          if(55>math>=53)
          math=3*1.33;
          else
          if(53>math>=50)
          math=3*1.00;
          else
          math=3*0;
          
          
          
          if(circuits>=90)
          circuits=3*4.00;
          else
          if(90>circuits>=85)
          circuits=3*3.66;
          else
          if(85>circuits>=80)
          circuits=3*3.33;
          else
          if(80>circuits>=75)
          circuits=3*3.00;
          else 
          if(75>circuits>=70)
          circuits=3*2.66;
          else
          if(70>circuits>=65)
          circuits=3*2.44;
          else
          if(65>circuits>=60)
          circuits=3*2.00;
          else
          if(60>circuits>=55)
          circuits=3*1.66;
          else
          if(55>circuits>=53)
          circuits=3*1.33;
          else
          if(53>circuits>=50)
          circuits=3*1.00;
          else
          circuits=3*0;
         
          
          
          if(solid>=90)
          solid=3*4.00;
          else
          if(90>solid>=85)
          solid=3*3.66;
          else
          if(85>solid>=80)
          solid=3*3.33;
          else
          if(80>solid>=75)
          solid=3*3.00;
          else 
          if(75>solid>=70)
          solid=3*2.66;
          else
          if(70>solid>=65)
          solid=3*2.33;
          else
          if(65>solid>=60)
          solid=3*2.00;
          else
          if(60>solid>=55)
          solid=3*1.66;
          else
          if(55>circuits>=53)
          circuits=3*1.33;
          else
          if(53>circuits>=50)
          circuits=3*1.00;
          else
          circuits=3*0;
         
          
          
          if(art>=90)
          art=3*4.00;
          else
          if(90>art>=85)
          art=3*3.66;
          else
          if(85>art>=80)
          art=3*3.33;
          else
          if(80>art>=75)
          art=3*3.00;
          else 
          if(75>art>=70)
          art=3*2.66;
          else
          if(70>art>=65)
          art=3*2.33;
          else
          if(65>art>=60)
          art=3*2.00;
          else
          if(60>art>=55)
          art=3*1.66;
          else
          if(55>art>=53)
          art=3*1.33;
          else
          if(53>art>=50)
          art=3*1.00;
          else
          art=3*0;
          
          
          
          if(pc>=90)
          pc=3*4.00;
          else
          if(90>pc>=85)
          pc=3*3.66;
          else
          if(85>pc>=80)
          pc=3*3.33;
          else
          if(80>pc>=75)
          pc=3*3.00;
          else 
          if(75>pc>=70)
          pc=3*2.66;
          else
          if(70>pc>=65)
          pc=3*2.33;
          else
          if(65>pc>=60)
          pc=3*2.00;
          else
          if(60>pc>=55)
          pc=3*1.66;
          else
          if(55>pc>=53)
          pc=3*1.33;
          else
          if(53>pc>=50)
          pc=3*1.00;
          else
          pc=3*0;
                
          total=esp+pc+circuits+solid+art+math;
          gpa=total/18;
          
          if(gpa>=3.4)
          printf("Excellent");
          else
          if(3.4>gpa>=2.8)
          printf("Very Good");
          else
          if(2.8>gpa>=2.4)
          printf("Good");
          else
          if(2.4>gpa>=2.0)
          printf("Weak");
          return (0);
    }

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    You have throughout your code constructs like:
    Code:
     if(3.4>gpa>=2.8)
    While this is legal C, it's not doing what you think it is. What it will do is first evaluate 3.4>gpa. If 3.4 is greater than gpa, it will evaluate to 1. If 3.4 is not greater than gpa, it will evaluate to 0. It will then take the result of that first expression, and apply it >=2.8. So it will either be 1>=2.8 or 0>=2.8. Both of which evaluate to 0, or false. The correct code for the above is:
    Code:
    if (3.4>gpa && gpa>=2.8)
    Or, probably more readably:
    Code:
    if (gpa < 3.4 && gpa >= 2.8)

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    46
    Thanks alot it worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 04:39 AM
  2. Prob with my gpa calculator program.
    By KidMan in forum C Programming
    Replies: 3
    Last Post: 01-22-2006, 08:34 PM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. GPA Program Problems
    By Clint in forum C Programming
    Replies: 3
    Last Post: 04-28-2005, 10:45 AM
  5. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM