Please help me with my assignment in c++!

Write a program that will input 10 numbers and display the sum in a ASCENDING ORDER.

please help me i really need this badly...

What you could do is, since you are getting inputs, you can make sure that
the inputs are greater than the last input.

example run :

Please enter a number  :  3
Please enter a number greater than 3 :  5
Please enter a number greater than 5 : 23
Please enter a number greater than 23 :  -42
<Invalid choice> 
Please enter a number greater than 23 : 45
//and so on

But I don't know if this is allowed for you.

Edited 7 Years Ago by firstPerson: n/a

What you could do is, since you are getting inputs, you can make sure that
the inputs are greater than the last input.

example run :

Please enter a number  :  3
Please enter a number greater than 3 :  5
Please enter a number greater than 5 : 23
Please enter a number greater than 23 :  -42
<Invalid choice> 
Please enter a number greater than 23 : 45
//and so on

But I don't know if this is allowed for you.

This is a great way to think outside the box, but I do not think it is a better solution because it delegates unnecessary work to the end user. I know I would be frustrated with software that did this to me, and I do not get frustrated easily. :D

This is a great way to think outside the box, but I do not think it is a better solution because it delegates unnecessary work to the end user. I know I would be frustrated with software that did this to me, and I do not get frustrated easily. :D

Yea, I think he should learn the "art of sorting" as it would provide
him with more knowledge. But what I said was just a suggestion.
Of course in a real software, it should be user friendly as possible.

If you want the lazy way out, you could also ask for 10 numbers in a loop and push them in a vector. Then use std::sort from <algorithm> to sort everything for you...
But that wouldn't half as fun as doing it yourself :)

please do help me the program goes like this;

  #include<iostream.h>
  void main()

  {
      int x;
      int no[10];

          cout<<"input 10 numbers"<<endl;
      for(x=0;x<=9;x++)
          cin>>no[x];
      for(x=0;x<=9;x++)
          cout<<no[x]<<endl;
  }

but i have to get the sum 0f the 10 numbers in ascending order this the outtput example:

                        1+1=2
                        2+2=4
                        3+3=6
                        5+5=10
                        4+4=8

i have to switch the 10 and the 8 in order,
please help me.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I suppose you could go for a really easy, but inefficient way of sorting by using 2 arrays. One could be your source array and the other would be your destination. Then just keep on looping though your source array. In loop 1 find the smallest number and copy it into your destination array. In loop 2 find the second smallest number, etc until you finish.

tank u so much necrolin but im a newbie can u give an example program please,

Next time use CODE TAGS!!

The First thing is that you might be using a very old compiler to compile your code. this is evident from #include <iostream.h> but asides that , I see that you have not implemented a sorting function in the first place.

Consider this :
Firstly before trying to sort out a array, try to think of a mechanism on how would you sort the array ?
Put that algorithm onto a paper and think if you can instruct the computer to follow your algorithm. And then start programming .

Once you have your algorithm ready all you need to do is to Put in the sum of the values in the array and then .. use the sort on them.

Given an array called arr with n elements where x and y are indexes of individual elements in the array. Use a nested loop to compare elements of arr as follows:

outer loop controls x, x varies from zero to less than n -1
  inner loop  controls y, y varies from x + 1 to less than n.
     if arrr[y] < arr[x]
        then swap arr[x] and arra[y]
  increment y by one each time through the inner loop
increment x by one each time through the outer loop

This means that each element in the array (that is, arr[x]) will be compared to each of the other elements in the array (that is, arr[y]) whose index, y, is higher than x and if element arr[y] is less than arr[x]then swap the value of the two element. That means at the end of the first inner loop arr[0] will be the smallest element in arr, at the end of he second run through the inner loop arr[1] will be the second smallest element, etc. This sorting process is frequently called bubble sorting. It isn't the fastest way to sort, but it is probably the easiest code to write that gets sorting done.

i am so thanful 4 all d replies..

but i realy nid to do dis now can any1 give an example program?
please.........

Well, On the basis of the algorithm provided by Lerner in the above post, I think that you should try to develop that methodology and when you have a problem then you could comeback to us.

This article has been dead for over six months. Start a new discussion instead.