# Thread: first c++ program(what am I doing wrong?)

1. ## first c++ program(what am I doing wrong?)

This is my first c++ program . I've written the majority of it and I'm getting weird results. Would someone look at it and help me figure out what I'm do wrong? How would I continue the program until the user is ready to quit? Use a while statement? My program is attached.

Problem Statement:
Write a program (in a single source code file) that will do the following (in order):
Ask the user to input three unique digits (0 through 9), and read in the input. (You may assume that the input is correct - no error checking needed).
Using these digits, create and output the six unique numbers that can be made using all combinations of the three digits.
Output the sum of the six numbers
Ask the user if they want to run the program again. The user will input a character. 'Y' or 'y' will be considered a "yes" response. Anything else should be considered a "no". If the response is yes, repeat the processing. If no, end the program.

Sample output
Welcome!
Enter three unique digits (0 through 9)
Enter digit 1: 8
Enter digit 2: 0
Enter digit 3: 3
The six new numbers:
803
830
83
38
380
308
Sum of the six new numbers: 2442

Would you like to run it again? (y/n): Y

2. not to do your homework for you, but the second and third numbers are actually 083 and 038. That's your first hint. Secondly outside of cout << means "shift left", think of it as like multiplication by a power of two
int a=4,b=2;
a<<b is a * 2^b
How to actually do this? well the first number you need has num1 in the hundreds place, num2 in the tens place and num3 in the one's place. hint hint

You don't need nearly as many variables as you seem to think you do, after you have printed the first number and added it to the total you don't need it anymore.

You also need a loop I suggest do { } while(something)

3. ## challenge

as a challenge to more advanced memebers, write this program using only two variables and no more than three operations to calculate the total. Fun!

4. ## i still don't understand

Grib,

Thanks.

5. given three numbers int a,b,c; what you seem to have to do is create a new number "starting" with a, followed by b followed by c. the easyest way to do this would be to just print out a b and then c, but your assignment does not allow this. We need make one number out of the three we have. To do this we use plain old math

num = a*100 + b*10 + c;

assuming each is less than 10 and greater than or equal to zero
cout << num << endl;
prints out abc, that is if a is 5 then num is 500 + something. if a is zero then num is just b*10+c and less than one hundred.

as to the challenge to others, let me clarify: calculate the total using only a,b,c and three operations(forget fewest variables). jlmac just add num to a total after you print it each time.