Thread: Sorting a set of numbers based on what the user inputs?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    7

    Sorting a set of numbers based on what the user inputs?

    I've looked around for some help on this but I can only find how to sort for a specific array size. The directions are as follows:

    Write a program that finds the largest in a series of numbers entered by the user. The program must prompt the user to enter numbers one by one. When the user enters a 0 or a negative number, the program must display the largest nonnegative number entered.

    Here is what I have so far:
    Code:
    int main(int argc, char *argv[])
    {
      /*This program will find the largest number in a series of positive numbers */
      /*entered one number at a time. Enter a 0 or negative number to end the loop*/
    
      int n, temp;
      int counter = 1;
      int largest = 0;
      printf("Enter a number:");
      scanf("%d", &n);
      while(n > 0)
      {
              printf("Enter a number:");
              scanf("%d", &n);
      }
      while(n <= 0)
      {
              while(counter <= n)
              {
              if(n > largest)
              {
                   temp = 0;
                   temp = largest;
                   largest = n;
              }
              else if(n < largest);
              {
                     temp = 0;
                     temp = largest;
                     largest = largest;
              }
              
              counter++;
      
              
              printf("The largerst number is: %d", &largest);
    }
    }
      system("PAUSE");	
      return 0;
     }
    I am using bloodshed if that makes any difference, please let me know what I need to change, thanks.
    Last edited by vmckoon2; 04-28-2010 at 10:14 PM. Reason: Bad syntax

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting numbers in descending order
    By Yunasnk in forum C++ Programming
    Replies: 2
    Last Post: 11-23-2003, 05:55 PM
  2. Sorting Random Numbers
    By kid kash in forum C++ Programming
    Replies: 4
    Last Post: 12-07-2002, 04:47 AM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. Replies: 6
    Last Post: 04-12-2002, 08:33 AM
  5. Action Based On User Input
    By Stealth in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2001, 05:38 AM