Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)

 Umairajmal 25Dec2010 11:10

Hi, guys i am umair. i am a beginer programmer in c++ and i have a problem. I want to add two old style British corrency(i.e, Pounds.Shillings.Pence e.g, 10.2.13). please tell me how can i do this.
I will be very thankful to you.

 Programming_Kills 25Dec2010 14:57

Can you please Explain What Actually you Want???

 Umairajmal 25Dec2010 19:59

Actually i want to make aprogramme that can add two old style British curency.The question is:

creat a programme that allow a user to enter two values in old style british curency and program should add them.
the old style british curency is:
pound.shilling.pence(e.g, 13.10.19)
in this situation
pound = 12s hillings.
shilling = 20 pence.

 jimblumberg 26Dec2010 00:58

What have you tried?

Jim

 Umairajmal 29Dec2010 15:19

sorry guys i am very busy in these days and i does not see my post.
My question is that i want to add two values of old style british corrency.
Plz tell me the formula for adding.

 jimblumberg 29Dec2010 19:21

What have you tried?

Post the code showing that you are trying.

This is your assignment and you must first show a good faith effort at completing your assignment before we will help.

Jim

 ThorAsgard 29Dec2010 21:26

Quote:
 Originally Posted by Umairajmal (Post 76575) sorry guys i am very busy in these days and i does not see my post. My question is that i want to add two values of old style british corrency. Plz tell me the formula for adding.
Is this the formula you mean

So there were 240d (that's pence) in £1 that's 12 (pence in a shilling) x 20 (shillings in a pound) - easy isn't it?

:happy:

 xpi0t0s 29Dec2010 23:43

You can do it two ways:

(1) you can write functions to convert between LSD and a number of D (for example 13.3.9 would be 13*240+3*12+9=3165), then for the two amounts you want to add, convert them to D, add the D sums together just using normal integer arithmetic and convert the result back, or

(2) you can add individual D values together and handle any overflow into the S calculation, then likewise for S and D, i.e.
D=D1+D2; if D>11 split into D<12 and overflow F;
S=S1+S2+F; if S>19 split into S<20 and overflow F;
L=L1+L2+F.

I would suggest (1), not because it's easier in the short run, but because sooner or later you are going to need these functions, so you may as well write them in the first instance then you can use them straight away.

 Umairajmal 5Feb2011 11:12