445,857 Members | 1,793 Online Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

# Here is my idea on how to do this program, but I cannot put it into action

 P: n/a I need help with this program, if anyone can give input. I can think of how to do it, but it is hard for me to put into the program. I realize that I am trying to separate out a certain digit number into its separate digits. For example, a single number like 43 to be split into 4 and 3. and that 43 is of the decimal system where the 4 belongs to the 10th and the 3 belongs to the unit place, which essentially means that 4 is a multiple of 10 and 3 is a multiple of 1. So I would need to divide them somehow. But how do I do this with a five digit number? I assume it is the same way, but cannot figure it out. Any guidance would be helpful. Thanks, Pixie. The program is: // digits.cpp #include using std::cout; using std::cin; using std::endl; int main() { int num; cout << "Enter a five-digit number: "; cin >> num; /* write a statement to print the left-most digit of 5-digit number */ /* write a statement that changes num from a 5-digits to 4-digits */ /* write a statement to print the left-most digit of 4-digit number */ /* write a statement that changes num from a 4-digits to 3-digits */ /* write a statement to print the left-most digit of 3-digit number */ /* write a statement that changes num from a 3-digits to 2-digits */ /* write a statement to print the left-most digit of 2-digit number */ /* write a statement that changes num from a 2-digits to 1-digit */ cout << num << endl; return 0; } Sep 29 '05 #1
3 Replies

 P: n/a Pixie wrote: I need help with this program, if anyone can give input. I can think of how to do it, but it is hard for me to put into the program. I realize that I am trying to separate out a certain digit number into its separate digits. For example, a single number like 43 to be split into 4 and 3. and that 43 is of the decimal system where the 4 belongs to the 10th and the 3 belongs to the unit place, which essentially means that 4 is a multiple of 10 and 3 is a multiple of 1. So I would need to divide them somehow. But how do I do this with a five digit number? I assume it is the same way, but cannot figure it out. Any guidance would be helpful. Thanks, Pixie. The program is: // digits.cpp #include using std::cout; using std::cin; using std::endl; int main() { int num; cout << "Enter a five-digit number: "; cin >> num; /* write a statement to print the left-most digit of 5-digit number */ /* write a statement that changes num from a 5-digits to 4-digits */ /* write a statement to print the left-most digit of 4-digit number */ /* write a statement that changes num from a 4-digits to 3-digits */ /* write a statement to print the left-most digit of 3-digit number */ /* write a statement that changes num from a 3-digits to 2-digits */ /* write a statement to print the left-most digit of 2-digit number */ /* write a statement that changes num from a 2-digits to 1-digit */ cout << num << endl; return 0; } See this FAQ: http://www.parashift.com/c++-faq-lit...t.html#faq-5.2 Cheers! --M Sep 29 '05 #2

 P: n/a "Pixie" wrote: I need help with this program, if anyone can give input. I can thinkof how to do it, but it is hard for me to put into the program.I realize that I am trying to separate out a certain digit number intoits separate digits. For example, a singlenumber like 43 to be split into 4 and 3. and that 43 is of the decimalsystem where the 4 belongs to the 10th You're heading down the wrong path here. The number is input to your program as a character string. All you need to do is grab the individual characters that make up that character string. -- Tim Slattery Sl********@bls.gov Sep 29 '05 #3

 P: n/a Pixie wrote: I need help with this program, if anyone can give input. I can think of how to do it, but it is hard for me to put into the program. I realize that I am trying to separate out a certain digit number into its separate digits. For example, a single number like 43 to be split into 4 and 3. and that 43 is of the decimal system where the 4 belongs to the 10th and the 3 belongs to the unit place, which essentially means that 4 is a multiple of 10 and 3 is a multiple of 1. So I would need to divide them somehow. But how do I do this with a five digit number? I assume it is the same way, but cannot figure it out. Any guidance would be helpful. Thanks, Pixie. You need the modulus operator 43%10 equals 3 543%100 equals 43 6543%1000 equals 543 and the divide operator 43/10 equals 4 543/100 equals 5 6543/1000 equals 6 Starting to get the idea? Put the modulus operator and the divide operator together in the right combinations and you'll get your assignment done. john Sep 29 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion. 