help getting program to test numbers

This is a discussion on help getting program to test numbers within the C Programming forums, part of the General Programming Boards category; hey guys im trying to get my program to test if a line of numbers from a ".dat" file is ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    41

    help getting program to test numbers

    hey guys im trying to get my program to test if a line of numbers from a ".dat" file is largest to smallest like 80 75 64 35. if it is then it should not count those as grades. it will count and assign grades to each score from a new line. if the set of numbers on the line are not from largest to smallest then it should stop and print a message. my program works within the bounds of 0-100 and anything out of those numbers are not grades.

    main:
    Code:
    #include <stdio.h>
    
    char assign_grade(int score);
    
    int main()
    {
        /* declarations */
        int score,good=0, bad=0, out=0;
        char grade, illegal = 'Z';
    
        /* keep getting input till EOF */
           while(scanf("%d", &score) != EOF)
           {
    
        /* if within the bounds */
        if (score>=0 && score<=100)
            {
        /* counts and prints passing grades */
        if (score >= 70 && score <= 100)
            {
               good = good + 1;
                        printf("%d: ", score);
                      grade = assign_grade(score);
                      printf("%c\n", grade);
            }
        /* counts and prints failing grades */
        if (score >= 0 && score <= 69) 
            {
             bad = bad + 1;
                     printf("%d: ", score);
             grade = assign_grade(score);
                    printf("%c\n", grade);
            }
            }
    
        /* count and prints illegal scores */
        if (score<0||score>100)
            {
             printf("%d: ", score);
             printf("illegal score!\n");
             out = out + 1;   /* counts illegal */
            }    
        }
        /* print total count of pass/fail/illegal grades */
        printf("Passing scores: %d\n", good);
        printf("Failing scores: %d\n", bad);
        printf("Illegal scores: %d\n", out);
    
         }
    function:
    Code:
     /* bounds for A/B/C/D/F/Illegal */
    #define ISA(c) (c>=90&&c<=100)
    #define ISB(c) (c>=80&&c<=89)
    #define ISC(c) (c>=70&&c<=79)
    #define ISD(c) (c>=60&&c<=69)
    #define ISF(c) (c>=0&&c<=59)
    #define ISN(c) (c<0&&c>100)
    
     /* assignment function */
    char assign_grade(int score)
    {
       /* testing scores and returning grade */
        if (ISA(score)) 
           return 'A';
    
         if (ISB(score)) 
           return 'B';
    
         if (ISC(score)) 
           return 'C';
    
         if (ISD(score)) 
           return 'D';
    
         if (ISF(score)) 
           return 'F';
        
        if (ISN(score))
        return 'Z';
    }
    dat:
    Code:
    75 80 70 60
    95
    85
    80
    75
    70
    68
    50
    104
    -10
    dat2:
    Code:
    90 80 70 60
    95
    85
    80
    75
    70
    68
    50
    104
    -10

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you program is failing in some way, then state what input causes it to fail, and whether your are receiving warnings from your compiler, or not. If you don't ask specific questions, it's difficult to give specific advise.

    For instance, what block of code is supposed to handle this testing, or is there one, currently?
    Last edited by Adak; 10-29-2011 at 03:07 AM.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    41
    Adak, currently there isnt one because I havent figured a way to make a new function to test numbers. i was going to assign the input into different declarations but that doesnt work out. the program is good and is doing what I want it to do but its not complete yet. im looking for advice on how to code a new function to test input before continuing on the loop

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Test-program
    By ScariuM in forum C Programming
    Replies: 6
    Last Post: 03-31-2011, 02:46 PM
  2. Math test program
    By giggleboo in forum C++ Programming
    Replies: 3
    Last Post: 12-15-2010, 11:38 AM
  3. Replies: 3
    Last Post: 09-08-2010, 11:26 AM
  4. Anybody know of a program to test efficiency?
    By John_ in forum Tech Board
    Replies: 2
    Last Post: 01-26-2006, 02:13 AM
  5. Looking for people with IIS to test my program
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-22-2003, 04:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21