program from book wont work

This is a discussion on program from book wont work within the C Programming forums, part of the General Programming Boards category; I copyed this program from book and it doesnt work right. I have reveiwed it and it is just like ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    25

    program from book wont work

    I copyed this program from book and it doesnt work right. I have reveiwed it and it is just like the book, but when I type EOF it gives me the message incorrect letter grade entered. enter a new grade. It gives that message twice and never gives me how many a,b,c,d,f, that were type in. i am pasteing the program, can someone help me out.

    Code:
    #include <stdio.h>
    
    
    
    int main()
    
    {
    
    	int grade;
    	int aCount = 0, bCount = 0, cCount = 0,
    		dCount = 0,fCount = 0; 
    
    	printf ( "Enter the letter grades.\n" );
    	printf ( "Enter the EOF	character to end input.\n" );
    
    	while ( ( grade = getchar() ) != EOF ) {
    
    		switch ( grade ) {
    
    			case 'A': case 'a':
    			++aCount;
    				break;
    
    			case 'B': case 'b':
    			++bCount;
    				break;
    
    			case 'C': case 'c':
    				++cCount;
    				break;
    
    			case 'D': case 'd':
    				++dCount;
    				break;
    
    			case 'F': case 'f':
    				++fCount;
    				break;			
    
    			case '\n': case ' ': 
    				break;
    
    			default:
    				printf ("Incorrect letter grade entered.");
    				printf (" Enter a new grade.\n");
    				break;
    
    		}
    
    	}
    
    	printf ( "\nTotals for each letter grade are:\n");
    	printf ( "A: %d\n", aCount);
    	printf ( "B: %d\n", bCount);
    	printf ( "C: %d\n", cCount);
    	printf ( "D: %d\n", dCount);
    
    		
    	
    
    	return 0;
    
    }

    thanks for your help
    cemock

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    25
    I figured it out have to press control z to end program lol
    I thought u had to type eof to end sorry for the post

  3. #3
    Black Mage Extraordinaire VegasSte's Avatar
    Join Date
    Oct 2002
    Posts
    167
    Just a little note to say when posting code, the last code tag is [/code] and not [\code] like in your post.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RSA C Program doesnt work
    By szpengchao in forum C Programming
    Replies: 0
    Last Post: 04-17-2009, 01:47 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  5. one function in my program won't work....
    By talz13 in forum C++ Programming
    Replies: 12
    Last Post: 04-06-2003, 01:19 PM

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