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 1263
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
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: - 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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |