Thread: Help needed :-(

  1. #16
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Elegant in its simplicity.
    Cool, so if I get a 69.5 in your class, I get an 'A'. I wish I had you for a professor in school

  2. #17
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    *cough* I guess I should have read your code before changing it.

    Code:
    // declaring the determine_grade function
    char determine_grade(float test_score)
    {
    	if (test_score >= 80 && test_score < 90)
    		return 'B';
    	else if (test_score >= 70 && test_score < 80)
    		return 'C';
    	else if (test_score >= 60 && test_score < 70)
    		return 'D';
    	else if (test_score >= 0 && test_score  < 60)
    		return 'F';
    	else
    		return 'A';
    }
    Of course, bithub, do you realize how difficult it would have been to get an A that way? But joking aside, the boundaries are correct now.
    wipe on -
    A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.
    - wipe off

  3. #18
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Code:
    char determine_grade(float test_score)
    {
      if (test_score >=90)
        return 'A';
      else if (test_score >= 80)
        return 'B';
      else if (test_score >= 70)
        return 'C';
      else if (test_score >= 60)
        return 'D';
      else 
        return 'F';
    }
    someone said something about simplicity?

    of course with the way our education system works I think
    Code:
    if (test_score < 60)
      return 'F';
    else if (test_score < 70)
      return 'D';
    else if (test_score < 80)
      return 'C';
    else if (test_score < 90)
      return 'B';
    else 
      return 'A';
    would be more efficient
    Last edited by ಠ_ಠ; 07-27-2009 at 04:43 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #19
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    Haha! Very true on both counts. One could simply change the way grades are calculated.

    Code:
    float calc_average(float score_1, float score_2, float score_3,
    				   float score_4, float score_5)
    {
    	float average;
    
    	average = (score_1 + score_2 + score_3 + score_4 + score_5) / 5.0;
    
    	if(average < 0)
    		average = 0.0f.
    
    	return (average <= 100) ? average : 100.0f;
    }
    Then one could use an array, which in this case is probably not any less expensive given the few possible outcomes for a grade.

    Code:
    char determine_grade(float test_score)
    {
      char *grades = "FDCBA";
      int index = (int)(test_score/10) - 6;
    
      if(index < -1)
        index = 0;
    
      return grades[index];
    }
    Hmmmm perhaps?

    Code:
    char determine_grade(float test_score)
    {
      char *grades = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDDDDDDDDDDCCCCCCCCCCBBBBBBBBBBAAAAAAAAAAA";
    
      return grades[(int)(test_score)];
    }
    Last edited by Cooloorful; 07-27-2009 at 05:08 PM.
    wipe on -
    A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.
    - wipe off

  5. #20
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    you run the risk of blowing the bounds of your array
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  6. #21
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    There, now it doesn't ;-)
    wipe on -
    A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.
    - wipe off

  7. #22
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    what if the score is less then 60 in the first case?
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  8. #23
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    True dat, ok its becoming overly convoluted even bothering with the first way. Well... both are overly convoluted, but the first method exceeds even my usual way of doing it. Fun is fun and all, but I highly recommend against either. A computer is never so overly bogged down that it can't handle calculating a letter grade without some crazy optimization.
    wipe on -
    A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.
    - wipe off

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  4. C++ Knowledge Needed For Making Graphic Games?
    By Krak in forum C++ Programming
    Replies: 14
    Last Post: 07-11-2003, 09:11 PM