help!!!repeated scentences error!!!

This is a discussion on help!!!repeated scentences error!!! within the C++ Programming forums, part of the General Programming Boards category; the problem is this.......... the sample output should be Code: Enter a grade (A-F):A Enter a grade (A-F):B Enter a ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    somewhere in terran
    Posts
    12

    Question help!!!repeated scentences error!!!

    the problem is this..........
    the sample output should be
    Code:
    Enter a grade (A-F):A
    Enter a grade (A-F):B
    Enter a grade (A-F):A
    Enter a grade (A-F):D
    Enter a grade (A-F):C
    Enter a grade (A-F):D
    Enter a grade (A-F):D
    Enter a grade (A-F):E
    Enter a grade (A-F):C
    Enter a grade (A-F):F
    number of credit:5
    number of pass:9
    number of fail:1
    BUT.....
    it shows up like this...
    Code:
    Enter a grade (A-F):A
    Enter a grade (A-F):
    Enter a grade (A-F):
    A
    Enter a grade (A-F):
    Enter a grade (A-F):
    A
    Enter a grade (A-F):
    Enter a grade (A-F):
    A
    Enter a grade (A-F):
    Enter a grade (A-F):
    A
    Enter a grade (A-F):
    Enter a grade (A-F):
    A
    number of credit:5
    number of pass:0
    number of fail:0
    the program is :
    Code:
    #include <stdio.h>
    
    int main (){
        int credit = 0, pass = 0, fail = 0, i;   //may be wrong
        char grade;
        
        for(i=1;i<=20;i++)                       //may be wrong
        {
            printf("Enter a grade (A-F):\n");    //may be wrong
            scanf("%c", &grade);
            if (grade<'A'||grade>='C') 
            credit++;
            else
            if(grade<='A'||grade>='E')
            pass++;
            else
            fail++;
        }
        printf("number of credit:%d\n", credit);
        printf("number of pass:%d\n", pass);
        printf("number of fail:%d\n", fail);
    
        
        system("pause");
        return 0;
    }

    what's wrong with it?
    why are there repeated scentences?

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Look at the code modified

    Code:
    #include <stdio.h>
    
    int main (){
      int credit = 0, pass = 0, fail = 0, i;   //may be wrong
      char grade;
    
      for(i=1;i<=20;i++)                       //may be wrong
        {
          printf("Enter a grade (A-F):\n");    //may be wrong
          scanf("%c", &grade);
          getchar(); // Added :)
          if (grade<'A'||grade>='C')
            credit++;
          else
            if(grade<='A'||grade>='E')
              pass++;
            else
              fail++;
        }
      printf("number of credit:%d\n", credit);
      printf("number of pass:%d\n", pass);
      printf("number of fail:%d\n", fail);
    
    
      system("pause");
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 03:39 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

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