473,396 Members | 1,671 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.

Seperating numbers

2
The assinment is i gotta prompt user to enter the number of five, ten twenty, fifty cent coins and one and two dollar coins they have then add em together.
The hard part is i need to store the number of cents as a integer and the number of dollars as an integer (not just one double)

So yeah
How can i seperate the number
123456 into the two numbers
1234 and 56

To display $1234.56
or any other way you could think of doing it

Thanks for any help
Aug 15 '08 #1
4 1265
blazedaces
284 100+
Make a class with an int cent variable and an int dollar variable.

As for your specific question, if you are inputted 123456 and you want to get 1234 and 56 extracted from it you should do the following:

First realize that 123456 = 6 *10^0 + 5*10^1 + 4*10^2 + 3*10^3 + 2*10^4 + 1*10^5.

AND realize that when you divide an integer will truncate the remainder.

With this you can do the following:

store 123456 and make a second variable 123456

divide by 100, you'll get 1234 (cause it's an int it'll throw the rest away). Now you have the first part. Then multiply by 100 again and you'll get 123400, subtract the original from that, 123456-123400 = 56, you have your second part, the cents.

Good luck,
-blazed
Aug 15 '08 #2
Nepomuk
3,112 Expert 2GB
With this you can do the following:

store 123456 and make a second variable 123456

divide by 100, you'll get 1234 (cause it's an int it'll throw the rest away). Now you have the first part. Then multiply by 100 again and you'll get 123400, subtract the original from that, 123456-123400 = 56, you have your second part, the cents.

Good luck,
-blazed
Much easier:
Expand|Select|Wrap|Line Numbers
  1. int total_cash = 123456;
  2. int dollars = total_cash / 100;
  3. int cents = total_cash % 100;
The % symbol is the so called modulo operator, which gives you the remainder of a division.
So, as 123456 / 100 = 1234 + 56 / 100 it will give you 56.

Greetings,
Nepomuk
Aug 15 '08 #3
Dargen
2
Tankyou so much guys!
Great help :P
Aug 15 '08 #4
blazedaces
284 100+
Much easier:
Expand|Select|Wrap|Line Numbers
  1. int total_cash = 123456;
  2. int dollars = total_cash / 100;
  3. int cents = total_cash % 100;
The % symbol is the so called modulo operator, which gives you the remainder of a division.
So, as 123456 / 100 = 1234 + 56 / 100 it will give you 56.

Greetings,
Nepomuk
Yes, much easier...

-blazed
Aug 15 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: TonyB | last post by:
Hi, I've searched the group and need more information and guidance on this issue I need to resolve next week. I work for the local school system and I am working on a way to parse a CSV file of...
4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
6
by: Jo K. | last post by:
I have a bounded field called Name. It's used to type in the full name of a customer (intentionally set up that way instead of seperating the first and last names) I would like to be able to...
0
by: AnkitAsDeveloper [Ankit] | last post by:
As all we know, in order to remove cyclic includes in C++ we seperate the declarations and definitions of classs and it's member in two files Header (*.h) and source files (*.cpp). This is not a...
5
by: raj | last post by:
i'm surely a newbie in python and on the go, I just tried to write a small app to change the gnome desktop background daily. It's working now making use of listdir() to find the contents of each...
7
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.