Create
a structure called sterling that stores money amounts in the old-style British
system. The members could be called pounds, shillings, and pence, all of type
int.
The
program should ask the user to enter a money amount in new-style decimal pounds
(type double), convert it to the old-style system, store it in a variable of
type struct sterling, and then display this amount in pounds-shillings-pence
format.
SOLUTION:
#include<iostream.h>
#include<conio.h>
/////////////////////////////////////////////////////////////
Define Structures
////////////////////////////////////////////////////////////
struct sterling
{
int
pounds,shillings,pence;
};
/////////////////////////////////////////////////////
Define Structure Variables
/////////////////////////////////////////////////////
sterling amount;
void main()
{
double d_pounds;
long t_pence;
clrscr();
/////////////////////////////////////////////////////////////////
Take Input
////////////////////////////////////////////////////////////////////
cout<<"Enter
amount in Decimal Pounds: ";
cin>>d_pounds;
//////////////////////////////////////////////////////////////
Convert Amount
////////////////////////////////////////////////////////////
t_pence=d_pounds*100;
amount.shillings=t_pence/12;
amount.pounds=amount.shillings/20;
amount.shillings=amount.shillings%20;
amount.pence=t_pence%12;
//////////////////////////////////////////////////////////////////////
Output
/////////////////////////////////////////////////////////////////////
cout<<"\nAmount
in Old format is: "<<amount.pounds<<"."
cout<<amount.shillings<<"."<<amount.pence;
getch();
}
OUTPUT:
0 comments: