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
4 1265
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, 123456123400 = 56, you have your second part, the cents.
Good luck,
blazed
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, 123456123400 = 56, you have your second part, the cents.
Good luck,
blazed
Much easier:  int total_cash = 123456;

int dollars = total_cash / 100;

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
Tankyou so much guys!
Great help :P
Much easier:  int total_cash = 123456;

int dollars = total_cash / 100;

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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...

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

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

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

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

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

by: newstips6706 
last post by:
1, 2, 3, 5, 7... PRIME Numbers
________________________________
Definitions
What is a PRIME Number ?

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

by: Charles Arthur 
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone

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

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

by: nemocccc 
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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 columnwise with in the specific length.
suppose the i have to...

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

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

by: Oralloy 
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bitfields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...

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