Thread: Input Numbers

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    25

    Input Numbers

    Hello again guys!
    So I've been working on a program that accepts 2 inputs a & b
    and does the following:
    Get another b number of inputs ,may contain negative nos and
    print the largest and the smallest input numbers.

    Here's my code : </3

    Code:
    {	
    	max = input;
    	min = input;
    	
    	while (count<=b)
      {	printf("--> Please enter another %d numbers\n", b);
       	scanf("%d", &input);
    	
          if ( input > max )
          {
             max = input;
    
          }
    
          if (input < min )
          {
             min = input;
    
          }
    
          count+=1;
       }
    
    }
       printf( "The biggest integer is %d\n", max );
    
       printf( "The smallest integer is %d\n", min );
    It only prints the smallest integer. i cant find the problem. Please help me find it. Thanks!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You aren't showing how you initialize anything. Also, you might consider a for loop here:
    Code:
    for( x = 0; x < nums; x++ )
    {
        read num
        if x is 0, this is the first number, so set min and max to num read
        if num < min set min
        if num > max set max
        
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Got it! Thanks!
    Last edited by bummielove; 07-23-2011 at 07:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input check problem with numbers
    By BlackSlash12 in forum C++ Programming
    Replies: 32
    Last Post: 11-30-2007, 02:20 AM
  2. Help on restricting input to a numbers only (or text only)
    By BongoBob in forum C++ Programming
    Replies: 6
    Last Post: 05-14-2006, 08:32 PM
  3. Input numbers using realloc
    By Horse22 in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 10:09 AM
  4. Just receive numbers (0-9) as input.
    By Vber in forum C Programming
    Replies: 1
    Last Post: 11-18-2002, 10:00 AM
  5. count numbers input
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 05-10-2002, 09:48 AM