Like Tree1Likes
  • 1 Post By quzah

Input Numbers

This is a discussion on Input Numbers within the C Programming forums, part of the General Programming Boards category; Hello again guys! So I've been working on a program that accepts 2 inputs a & b and does the ...

  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.
    AndrewHunter likes this.
    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 08: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, 09:32 PM
  3. Input numbers using realloc
    By Horse22 in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 11: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, 10:48 AM

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