Thread: String troubles

  1. #46
    Registered User
    Join Date
    Nov 2010
    Posts
    36
    Okay that works wonders i threw in the docking marks and 0 marks for blanks.

    Now the grading system is throwing me off a little bit. Ive done lots of these before, but for some reason i am drawing a blank on how i would like to do it.

    Code:
     grades = ((score/20)*100);
    		
    		if(grades<60)
    		{
    			printf("F\n");
    		}
    		else if(grades>=60&&grades<70)
    		{
    			printf("D\n");
    		}
    		else if(grades>=70&&grades<80)
    		{
    			printf("C\n");
    		}
    		else if(grades>=80&&grades<90)
    		{
    			printf("B\n");
    		}
    		else if(grades>=90&&grades<100)
    		{
    			printf("A\n");
    		}
    		else if(grades>=100)
    		{
    			printf("A+\n");
    		}
    Heres my somewhat correct yet failed attempt.

  2. #47
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Glad the solution works for you... now, please promise to take the time to understand how it works...

    For the new problem...
    It might help you to toss in a temporary printf() so you can see the result of your calculation...

    edit... I tested your letter grades and the score calculation is all wonky. However, when I gave 5 points for each question and used score (instead of grades) in the if - elseif set you provided, it did grade the scores properly.
    Last edited by CommonTater; 11-23-2010 at 02:30 PM.

  3. #48
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    A few questions/potential problems:
    1. Are you giving +1 or +2 points for a correct answer. +2 would mean a max score of 40, not 20. Adjust your divisor as necessary.
    2. grades = ((score/20)*100); is integer division. Unless the score is greater than 20, (score/20) will return zero. Either multiply by 100 first, then divide by 20 (should be equivalent to multiply by 5 actually), or cast your score to a float before all this, like so (((float) score)/20)*100.

    Also, your if-else is generally fine, but you could simplify, like so
    Code:
    if (grade < 60) {
        printf("F\n");
    }
    else if (grade < 70) {  // the first clause guarantees that, if we get here, grade >= 60
    }
    else if (grade < 80) {  // again, here we're guaranteed grade >= 70
    }
    ...

  4. #49
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    anduril ... excellent suggestion for the if-else !

    The final score can be fixed very nicely by simply giving 5 points for each correct answer.

  5. #50
    Registered User
    Join Date
    Nov 2010
    Posts
    36
    haha there we go i knew something was up but i forgot that my division originally would leave a decimal result which would require a float type variable. As far as my grading goes I know the max score is 40 and the min score is -40. But seeing as there are 20 questions. I am just going to assume the test will be out of 20 and not 40.

    Okay thank you very much my question has been completed fully to the standards that i wanted. I thank you CommonTater and anduril462 for being patient with my learning ability. I hope to one day be able to help you.
    Last edited by Annihilate; 11-23-2010 at 05:14 PM.

  6. #51
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Annihilate View Post
    Okay thank you very much my question has been completed fully to the standards that i wanted. I thank you CommonTater and anduril462 for being patient with my learning ability. I hope to one day be able to help you.
    No worries... I've kind of enjoyed doing this....

    As far as helping me, well that million dollar donation you were contemplating would be nice...

  7. #52
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Glad you learned something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM