Thread: Help me ! easy c program

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    9

    Question Help me ! easy c program

    help me please
    I can not continue

    and am i right?
    Q: input 10 students mark ,0-59mark is grade C ,
    60-75 mark is grade B ,76-100 mark is grade A ,
    then print the grade A ,B ,C amount .

    Code:
    /* prog6_9,  */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    
    {
        int num1 ,num2 ,num3;
        printf("mark\n");
        scanf("&#37;d%d%d",&num1,&num2,&num3);
        
        if(num1<59)
            printf("c\n");
        else if(num1<75)
                    printf("b\n");
            else
                    printf("a\n");
        
        if(num2<59)
            printf("c\n");
        else if(num2<75)
                    printf("b\n");
            else
                    printf("a\n");
        
        
        if(num3<59)
            printf("c\n");
        else if(num3<75)
                    printf("b\n");
            else
                    printf("a\n");
        
            
        
        system("pause");
        return 0;
    }
    Last edited by DINORS; 06-27-2008 at 01:55 AM.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Nope. You're wrong.

    You need to input 10 grades, and output the amount of A's, B's, and C's.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    9
    thx
    how to do ?

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    147
    Hi
    I don't know what exactly you want to do. But if you want enter mark for 10 students, I would write as follow (take into account that I have write it in a noteped, no compiler):

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define   TOTAL_STUDENTS   10
    
    int main(void)
    
    {
    	int m = 0;
            int marks[3] = {0,0,0};
    
    	for (int student = 0; student <  TOTAL_STUDENTS; student++) {
    		printf ("\nType mark for student &#37;d .... ",student);
    		scanf("%d",m);
    		if (m<59) {
    			marks[0] ++;
    		} else if (m<75) {
    			marks[1] ++;
    		} else {
    			marks[2] ++;
    		}
    	}
    	printf("There are %d with mark A.\n",mark[0]);
    	printf("There are %d with mark B.\n",mark[1]);
    	printf("There are %d with mark C.\n",mark[2]);
    }

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    And since you're doing this kid's homework, I won't point out the obvious error(s) in your code. Provide hints and tips and such. Don't do the work for them.

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    9
    thx
    thx

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    9

    Talking

    Quote Originally Posted by MacGyver View Post
    And since you're doing this kid's homework, I won't point out the obvious error(s) in your code. Provide hints and tips and such. Don't do the work for them.

    yes
    i am a junior
    i study by oneself .

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    9

    Lightbulb

    Quote Originally Posted by Kempelen View Post
    Hi
    I don't know what exactly you want to do. But if you want enter mark for 10 students, I would write as follow (take into account that I have write it in a noteped, no compiler):

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define   TOTAL_STUDENTS   10
    
    int main(void)
    
    {
    	int m = 0;
            int marks[3] = {0,0,0};
    
    	for (int student = 0; student <  TOTAL_STUDENTS; student++) {
    		printf ("\nType mark for student &#37;d .... ",student);
    		scanf("%d",m);
    		if (m<59) {
    			marks[0] ++;
    		} else if (m<75) {
    			marks[1] ++;
    		} else {
    			marks[2] ++;
    		}
    	}
    	printf("There are %d with mark A.\n",mark[0]);
    	printf("There are %d with mark B.\n",mark[1]);
    	printf("There are %d with mark C.\n",mark[2]);
    }


    sorry
    it can not compile & run
    and i do not understand !

  9. #9
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by DINORS View Post
    sorry
    it can not compile & run
    and i do not understand !
    Ask specific questions! What part doesn't compile? What's the compiler error? What line don't you understand?

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  10. #10
    Registered User
    Join Date
    Jun 2008
    Posts
    9
    for (int student = 0; student < TOTAL_STUDENTS; student++) {


    <<<DO NOT UNDERSTAND

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by DINORS View Post
    for (int student = 0; student < TOTAL_STUDENTS; student++) {


    <<<DO NOT UNDERSTAND
    It uses C99 standard, which, like C++, allows that you declare/define new variables just about anywhere in the code. Remove the "int" in the above line, and add "int student" next to your m and marks variable definitions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by DINORS View Post
    for (int student = 0; student < TOTAL_STUDENTS; student++) {


    <<<DO NOT UNDERSTAND
    What part? The variable declaration? What a for loop is? What the individual parts do? ASK SPECIFIC QUESTIONS!

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  13. #13
    Registered User
    Join Date
    Jun 2008
    Posts
    9
    i have not learn for loop .

    now i know if else go to case switch break .

  14. #14
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You'll need to learn loops to do this properly. Start learning.

  15. #15
    Registered User
    Join Date
    Jun 2008
    Posts
    9
    can it just use if else switch goto ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Macro Program
    By daspope in forum Windows Programming
    Replies: 5
    Last Post: 04-25-2004, 04:02 AM
  4. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM