So, I got to write program which lets you to choose number between 1 and 9 and writes down all two-digit numbers which contains that number.
For example I write number 3 it writes down following:
13 23 30 31 32 33 34 35 36 37 38 39 43 53 63 73 83 93
What I need help with is how to check if number has that digit I have written before. To be more accurate I know I should have 2 variables because it's two-digit and then I will have to check if one of it has the digit. But question is how to decompose each number to two separate numbers.
I'm quite new in C++ programming. Thank you in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cout <<"Insert positive number: ";
(what to write here)
You do not necessarily need to split the number. Much of what you need can be done the basic arithmetic operators of c++.
Since you are only handling numbers from 10 to 99, the number can only be in one of two positions the ones position, or the tens position. Therefore inside your loop you will need 2 conditions.
Condition 1, does the ones position have the number
In your example these are 13,23,33,43,53,63,73,83,93.
If it does print out the value.
Hint: look into the modulo (%) operator
Condition 2, does the tens position have the number
In your example these are the values 30,31,32,33,34,35,36,37,38,39
If it does print the value.
Hint: these begin with number*10.
If you execute the conditions above you will have the expected output with the exception of the number that has both the tens and the ones will be printed twice.
13 23 30 31 32 33 33 34 35 36 37 38 39 43 53 63 73 83 93
You will need to find a way to exclude this number in one of the conditions above
Hint: an inner conditional loop might be useful.