Don't like ads? PRO users don't see any ads ;-)

[C++] Pounds Shillings Pennies

By: Jeclipse on Aug 3rd, 2012  |  syntax: C++  |  size: 0.89 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.         int pences,shillings=0,pounds=0, original;
  7.         do{
  8.                 cout<<"How many pences:";
  9.                 cin>>pences;//input pences
  10.         }while(pences<0||pences>10000);//verify range
  11.         original=pences;// set an original value for last output
  12.         while(pences/240.0>=1)//while pences is divisible by 240, increment pounds
  13.         {
  14.                 pounds++;
  15.                 pences-=240;//subtract that which has been turned into a pound
  16.         }
  17.         while(pences/12.0>=1)//while pences is divisible by 12, increment shillings
  18.         {
  19.                 shillings++;
  20.                 pences-=12;//subtract that which has been turned into a shilling
  21.         }
  22.         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
  23.         system("pause");
  24.         return 0;
  25. }