Please support our C++ advertiser: Programming Forums
Views: 5212 | Replies: 2
![]() |
•
•
Join Date: Jul 2005
Posts: 47
Reputation:
Rep Power: 4
Solved Threads: 0
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
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];
}•
•
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,330
Reputation:
Rep Power: 7
Solved Threads: 44
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?
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?
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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode