I have a c++ project that is due on friday. please help :(
Codes should not be too advanced. Use loop or array.

Introduction:
An interesting sequence of numbers can be generated using any given integer using the following procedure:

  1. First, arrange the digits of the given number in ascending order.

  2. Next, arrange the same digits in descending order. 3. Find the difference between the two arranged numbers. Use this as the next number in the sequence.

The sequence will eventually repeat at 0 (if all digits are the same) or, after a small number of iterations, a short sequence common for all numbers of the same number of digits. For 3- and 4-digit numbers, these are the single numbers 495 and 6174.

Example:
For the 3-digit number 252, the sequence generated is 225, 297, 693, 594, 495, 495, … as shown below.
n(0) = 252
n(1) = 522 – 225 = 297
n(2) = 972 – 279 = 693
n(3) = 963 – 369 = 594
n(4) = 954 – 459 = 495
n(5) = 954 – 459 = 495

For the 4-digit number 3087, the sequence generated is 3087, 8352, 6174, 6174, … as shown below.
n(0) = 3087
n(1) = 8730 – 0378 = 8352
n(2) = 8532 – 2358 = 6174
n(3) = 7641 – 1467 = 6174

Problem: Write a program that will generate the described sequence for any given 4-digit number.

Input: The program shall accept a 4-digit integer and use this as the initial number.

Output: The program shall list the sequence generated until it reaches 0 or 6174.

Is there any particular part you are stuck with?
Posting up what you have done already makes it far more likely someone will help you. Requests to do your homework for you don't get much of a response.

If you haven't started, break it down into what it is asking of you:
sort 4 digits highest to lowest
sort the same 4 digits lowest to highest
subtract lowest from highest
check result
input new number or stop

If you handle each part as a separate problem you'll probably find you step through it pretty quickly.

Comments
well said!

If you handle each part as a separate problem you'll probably find you step through it pretty quickly.

correct.

your questions is not difficult. you can solve the homework by breaking it down into smaller parts. and these parts may be of:-

step 1. sort the digits (in ascending order)
step 2. sort the step1's answer in descending order
step 3. subtract step2-step1 and goto step1(with step3's answer).
it continues till you want.

Comments
Well said!
This article has been dead for over six months. Start a new discussion instead.