
[C++] Pounds Shillings Pennies
By:
Jeclipse on
Aug 3rd, 2012 | syntax:
C++ | size: 0.89 KB | hits: 18 | expires: Never
#include <iostream>
using namespace std;
int main()
{
int pences,shillings=0,pounds=0, original;
do{
cout<<"How many pences:";
cin>>pences;//input pences
}while(pences<0||pences>10000);//verify range
original=pences;// set an original value for last output
while(pences/240.0>=1)//while pences is divisible by 240, increment pounds
{
pounds++;
pences-=240;//subtract that which has been turned into a pound
}
while(pences/12.0>=1)//while pences is divisible by 12, increment shillings
{
shillings++;
pences-=12;//subtract that which has been turned into a shilling
}
cout<<"In "<<original<<" pences you will find "<<pounds<<" pounds "<<shillings<<" shillings and "<<pences<<" pennies"<<endl;//output original pences in pounds shillings and pennies, what is leftover of the variable cannot make a full shilling hence it is in pennies
system("pause");
return 0;
}