473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2572

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's...
14
by: Daniel Chartier | last post by:
Hello. I work in the paper industry and we recently had someone (the original author) from within the company make a program for preventive maintenance. However, it had some bugs and we wanted...
0
by: arbpen2003 | last post by:
This is driving me crazy. The markup is valid, the CSS is valid, I'm serving it right, and I still cannot figure out why I cannot get the cursor into the form element. I have tried on Opera,...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
5
by: bissatch | last post by:
Hi, I have been trying to come up with an idea to reduce double submissions where a user clicks refresh and, for example, another row is INSERT into a table. Originally, I would have a form...
6
by: CJ | last post by:
Okay, same program, different issue. Thanks to the help that I was given I was able to complete my program to find variables in a list that were repeated, and display them once, and how many times...
1
by: christopherpriest | last post by:
I have taken over a php web site. Once you login you are given six menu choices. Each option is or can be independant of the others. They each modify the same database but in different ways. On...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.