469,943 Members | 2,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

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

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 <iostream>

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 2462

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 <iostream>

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
"Pixie" <AP**********@gmail.com> 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


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
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.

Similar topics

12 posts views Thread by R | last post: by
14 posts views Thread by Daniel Chartier | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
6 posts views Thread by CJ | last post: by
1 post views Thread by christopherpriest | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.