RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 5212 | Replies: 2
Reply
Join Date: Jul 2005
Posts: 47
Reputation: karen_CSE is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
karen_CSE karen_CSE is offline Offline
Light Poster

ascending order

  #1  
Jul 20th, 2005
Hi, I'm supposed to make a program that asks the user how many integers they want to input, then prompt them to enter those integers. and then I'm supposed to put those integer into ascending order. How do I do that?

this is my code so far
#include <iostream.h>

void main (void)
{
	int *array, num;

	cout << "How many integers do you wish to allocate?";
	cin >> num;

	array = new int[num+1];
	if (array == NULL)		
	{						
		cout << "Error allocating memory!\n";
		return;
	}

	cout << "Enter the integers here: \n"; 
	for (int count =0; count < num; count++)
	{
		cout << "Integer # " << (count +1) << ": ";
		cin >> array[count];
	}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,330
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 44
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: ascending order

  #2  
Jul 20th, 2005
You should use #include <iostream>, not #include <iostream.h>.

You should use int main(), not void main(void).

Judging by your style of code, it seems that for whatever reason, you're not using the standard library. (You could use the std::sort function.) In that case, you'll want to write a subroutine that, when given a pointer to an array of integers and the length of the array, rearranges the elements in ascending order.

How would you do that, you say? Well, how would you put a deck of cards in ascending order? There are many ways.

I'm sure you'll soon get some people posting their own functions or giving code for using the already-existing std::sort function (which you could just look up anyway), but since you seem to be learning, it's much better to figure it out yourself.

I already gave you a hint: how would you go about systematically sorting a deck of cards?
Reply With Quote  
Join Date: Jul 2005
Location: Iceland
Posts: 104
Reputation: Alvein is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Alvein's Avatar
Alvein Alvein is offline Offline
Junior Poster

Re: ascending order

  #3  
Jul 21st, 2005
Though it's not a thing to learn by cut-n-pasting other's source code, it's not a thing to re-invent yourself either (mainly if you're a beginner).

Look here for a really simple tutorial about sorting, with source code. Save the site for future reference. It has a lot of content for you.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:28 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC