three questions about hw assignment

I have to do three small programs that use loops. I know how to do the loops but am unsure about how to do the rest for exercises 1 and 2. I think that I can do exercise 3 fully on my own.

For the first part, I have to calculate the sum of the integer entered.

If the user typed in 698, how would I commute the sum? Would I declare sum= integer? (interger being the number entered).

Sample:

Please input an integer between 0 and 1000: 1001

* Number not in 0-1000 range. Please re-enter: -1

* Number not in 0-1000 range. Please re-enter: 456

Sum of the digits is 15

For the second one, the user has to enter 3 intergers and they have to be sorted from smallest to largest. I don't know how to get them sorted from smallest to largest.

Sample run:

Input integer 1 : 34

Input integer 2 : 200

Input integer 3 : -14

Sorted : -14 <= 34 <= 200

Re: three questions about hw assignment

Quote:

*Originally posted by jlmac2001 *

**For the first part, I have to calculate the sum of the integer entered. **

If the user typed in 698, how would I commute the sum? Would I declare sum= integer? (interger being the number entered).

Sample:

Please input an integer between 0 and 1000: 1001

* Number not in 0-1000 range. Please re-enter: -1

* Number not in 0-1000 range. Please re-enter: 456

Sum of the digits is 15

For that one, suggest writing a function that will return a digit at a specified spot in an integer.

Code:

`int stripDigit(int num, int place);`

// if place == 1, return ones place digit

// if place == 2, return tens place digit, etc.

stripDigit(456, 2) == 5;

That's how I'd do it, anyway.