We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,280 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

display in acending order.

HI! could anyone help me out in editing the following code so that the list of number is displayed in ascending order. thanks.

#include <iostream.h>

void main()
{
    int count;
    cout << "Enter a number: ";
    cin >> count;
    while (count > 0)
    {
   cout << count << endl;
        --count;
    }      

}
2
Contributors
3
Replies
28 Minutes
Discussion Span
2 Years Ago
Last Updated
4
Views
rizzi143
Newbie Poster
21 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

No one here will re-write it for you (or at least they shouldn't).

Right now you're taking the user's input and counting down.

I suggest you start by first establishing a way to count up from (0) to a certain max value (10 for example).

Once you figure that out, adapt it to stop at the user's input value instead.

A suggestion, you may want to consider using a for loop instead of a while loop, they're better for this type of thing.

Fbody
Posting Maven
2,929 posts since Oct 2009
Reputation Points: 833
Solved Threads: 394
Skill Endorsements: 5

ya thanks for reply. i wasnt expecting a rewrite though. i just a jump start a hint to make it work. and i only need to use while loop.

rizzi143
Newbie Poster
21 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

>>...i just a jump start a hint to make it work. and i only need to use while loop.
I gave you a hint. Here's another:
Don't use the decrement operator. Use the increment operator instead, then adjust your loop's control condition accordingly.

If you have to use a while loop, it's doable, just less convenient.

Fbody
Posting Maven
2,929 posts since Oct 2009
Reputation Points: 833
Solved Threads: 394
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0857 seconds using 2.71MB