RAVIANS COLLEGE OF SCIENCE PATTOKI: Question No.10

Question No.10

10. In the heyday of the British empire, Great Britain used a monetary system based on pounds,
shillings, and pence. There were 20 shillings to a pound, and 12 pence to a shilling. The notation for
this old system used the pound sign, £, and two decimal points, so that, for example, £5.2.8 meant
5 pounds, 2 shillings, and 8 pence. (Pence is the plural of penny.) The new monetary system,
introduced in the 1950s, consists of only pounds and pence, with 100 pence to a pound (like U.S.
dollars and cents). We’ll call this new system decimal pounds. Thus £5.2.8 in the old notation is
£5.13 in decimal pounds (actually £5.1333333). Write a program to convert the old pounds-
shillings-pence format to decimal pounds. An example of the user’s interaction with the program
would be

Enter pounds: 7
Enter shillings: 17
Enter pence: 9
Decimal pounds = £7.89



In both Borland C++ and Turbo C++, you can use the hex character constant ‘\x9c’ to represent the
pound sign (£). In Borland C++, you can put the pound sign into your program directly by pasting it
from the Windows Character Map accessory.

ANSWER BY WAJID

#include
#include
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!1 pound = 20 shilling
!1 shilling = 12 pence
!so 1 pound = (20*12) 240 pence [in old system]
!also 1 pound = 100 pence [in new system]
!hence the transformation formula is :
!new_pence = (old_pence*100)/240
---------------------------------------------------------------------
!number of pence{old_pence} = (input_shillings*12) + input_pence
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void main(void)
{
int pounds, shillings, pence;
do{
cout<<"Enter pounds : "; cin >>pounds;
cout<<"Enter shillings : "; cin >>shillings;
cout<<"Enter pence : "; cin >>pence;
pence = ((shillings*12)+pence)*100/240;
//To make the programme more really (pence must not pass value 100).
if (pence >= 100){
//shillings here is only a gate, not by it's mean at all.
shillings = pence%100;
pounds += (pence-shillings)/100;
pence = shillings;}
cout<<"Decimal pounds = \x9c"< cout<<"\n !Press c to continue or any key to exit."< }while(getch()=='c');
}

BEST OF LUCK

1 comment:

Copyright © RAVIANS COLLEGE OF SCIENCE PATTOKI Urang-kurai