Thread: newbie programmer - needs help bad.

  1. #16
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    I suggest you get your text book and review the section on loops and the section/chapter pertaining to condition statements.

    Your fundamental flaw is not understanding the logic behind the if() statement.
    Last edited by Scribbler; 10-18-2004 at 01:23 PM.

  2. #17
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68
    Code:
    #include <stdio.h>
    
    int main()
    {
    	int total;
    	int smallest;
    	int largest;
    	int counter;
                    int integer;
    	
    	total = 0;
    	counter = 0;
    	largest = 0;
    	smallest = 9;
        
    
    	
            printf("Enter a one digit integer (0,1,2,3,.,8,9 or -1 to quit): ");
    	scanf("%d", &integer);
    
    	while( integer >=0) 
            { 
            total = total + integer; 
            counter = counter + 1;
             
            if (integer > largest) 
                largest = integer; 
            if (integer < smallest) 
               smallest = integer;
            
            printf("Enter a one digit integer (0,1,2,3,.,8,9 or -1 to quit): "); 
                    scanf("%d", &integer ); 
             }
     
           
            if (count!=0)
    {  
           printf( "The smallest digit entered was %d\n", smallest ); 
             printf( "The largest digit entered was %d\n", largest ); 
             printf( "The total of the digits entered was %d\n", total ); 
             printf( "Goodbye!!\n" );
    } 
                else 
                    printf("No digits were entered\n\n\nGoodbye!!\n"); 
                 
             
         
    
    	return 0;
    }

  3. #18
    Registered User
    Join Date
    Sep 2004
    Posts
    4
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int main() {
    	int high = 0, low = 9, sum=0, in=0;
    	
    	while ( in != -1 ) {
    		printf("\nEnter a digit or -1 to quit: ");
    		scanf("%d", &in);
    		
    		if ( in != -1 )	sum += in;
    		else 
    			break;
    		if ( in >= high )
    			high = in;
    		else if ( in <= low )
    			low = in;
    	}
    	printf("\nThe smallest digit entered was: %d\n", low);
    	printf("The largest digit entered was: %d\n", high);
    	printf("The total of the digits entered was: %d\n", sum);
    	return 0;
    }
    Don't like to hand code to people but this may help you ONLY if you look at your text book while looking at this. Look at it, study it and understand how it works.

    Nate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poker bad beats
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 01-15-2005, 11:42 PM
  2. How bad is bad
    By caroundw5h in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 11-12-2004, 09:26 AM
  3. If you are employed as a programmer, please look
    By Flood Fighter in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 09-28-2004, 02:35 AM
  4. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM
  5. good news and bad news
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 10-27-2001, 07:31 AM