Thread: Input student grades

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    5

    Input student grades

    I was given a task to create a program that:



    1. convert to grade
    2. calculate number of every grade like if there's inputted 5 times a score that equal to A then A = 5
    3. calculate average of score (using function)
    4. print stars depending of every grade A = 5 =*****, b = 2 = **


    I couldn't figure out the number 2, i think there's a small problem with my code

    Code:
    #include <stdio.h>
    #include "func.h"
    
    
    int main()
    {
    	int score, avg, count, total, student, aCount, bCount, cCount, dCount, eCount, k, skor, sick, haz;
    	total = 0;
    	student = 1;
    	aCount = 0;
    	bCount = 0;
    	cCount = 0;
    	dCount = 0;
    	eCount = 0;
    	char grade;
    
    
    	while (student <=10){
    	printf("Please enter the score: ");
    	scanf("%d", &score);
    	sick = score;
    	haz = counting(sick, aCount, bCount, cCount, dCount, eCount);
    	student++;
    	total = total + score;
    	grade = score2grade(score);
    	printf("Score = %d => grade=%c\n", score, grade);
    	}
    	avg = average(avg, total);
            printf("The Average is %d\n", avg);
    	printf("A: %d = ", aCount);
    		for(k=1; k<=aCount;k++){
    			printf("%s", "*");}
                            printf("\n");
    	printf("B: %d = ", bCount);
    		for(k=1; k<=bCount;k++){
    			printf("%s", "*");}
                            printf("\n");
    	printf("C: %d = ", cCount);
    		for(k=1; k<=cCount;k++){
    			printf("%s", "*");}
                            printf("\n");
    	printf("D: %d = ", dCount);
    		for(k=1; k<=dCount;k++){
    			printf("%s", "*");}
                            printf("\n");
    	printf("E: %d = ", eCount);
    		for(k=1; k<=eCount;k++){
    			printf("%s", "*");}
    			printf("\n");
    	return 0;
    }
    and the function
    Code:
    #include <stdio.h>
    
    
    int counting(int sick, int aCount, int bCount, int cCount, int dCount, int eCount)
    {
            if (sick >= 85) {aCount++;}
                    else if(sick >= 70) {bCount++;}
                            else if(sick >= 60) {cCount++;}
                                    else if(sick >= 55) {dCount++;}
                                            else {eCount++;}
    }
    
    
    char score2grade(int score)
    {
    	if (score >=85) return 'A';
    		else if(score >=70) return 'B';
    			else if(score >= 60) return 'C';
    				else if(score >= 55) return 'D';
    					else return 'E';
    }
    
    
    int average(int avg, int total)
    {
    	avg = total/10;
    }


    If you can help me a little I'll appreciate it.
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Have you learned about pointers or pass by address?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Oct 2019
    Posts
    5
    Quote Originally Posted by stahta01 View Post
    Have you learned about pointers or pass by address?

    Tim S.
    No i haven't

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by andre2539 View Post
    No i haven't
    Then, you need to know that functions can only return one value at most per function.
    I suggest you reread the book about using functions.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    int counting(int sick, int aCount, int bCount, int cCount, int dCount, int eCount)
    {
            if (sick >= 85) {aCount++;}
                    else if(sick >= 70) {bCount++;}
                            else if(sick >= 60) {cCount++;}
                                    else if(sick >= 55) {dCount++;}
                                            else {eCount++;}
    }
    The above will not do what you want.

    Code:
    void counting(int sick)
    {
            if (sick >= 85) {aCount++;}
                    else if(sick >= 70) {bCount++;}
                            else if(sick >= 60) {cCount++;}
                                    else if(sick >= 55) {dCount++;}
                                            else {eCount++;}
    }
    The above likely will do what you want; but, it is considered poor programming to use Global variables most of the time. But, this might be a time to use them because you do not yet know pass by value.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-01-2014, 08:14 AM
  2. Replies: 2
    Last Post: 08-30-2014, 11:07 PM
  3. Replies: 5
    Last Post: 09-12-2012, 10:21 PM
  4. c program on grades of a student
    By galmca in forum C Programming
    Replies: 14
    Last Post: 09-29-2004, 03:07 PM
  5. Replies: 13
    Last Post: 08-15-2002, 09:20 AM

Tags for this Thread