newbie programmer - needs help bad.

This is a discussion on newbie programmer - needs help bad. within the C Programming forums, part of the General Programming Boards category; I suggest you get your text book and review the section on loops and the section/chapter pertaining to condition statements. ...

  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 02: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

Page 2 of 2 FirstFirst 12
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, 03:35 AM
  4. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 03: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, 08:31 AM

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