Answer to Question #98707 in C++ for Muhammad Asim

Question #98707
Write a program that repeatedly asks the user to enter two money amounts expressed in old-style British currency: pounds, shillings, and pence. (See Exercises 10 and 12 in Chapter 2, “C++ Programming Basics.”) The program should then add the two amounts and display the answer, again in pounds, shillings, and pence. Use a do loop that asks the user whether the program should be terminated. Typical interaction might be Enter first amount: £5.10.6 Enter second amount: £3.2.6 Total is £8.13.0 Do you wish to continue (y/n)? To add the two amounts, you’ll need to carry 1 shilling when the pence value is greater than 11, and carry 1 pound when there are more than 19 shillings.
1
Expert's answer
2019-11-15T10:47:10-0500

#include <iostream>


using namespace std;


int main()

{

  int pounds_2, shillings_2, pennies_2,pounds_1, shillings_1, pennies_1;

  int total_pounds, total_shillings, total_pennies;

  string answer;

  do

  {

    pounds_2 = 0, shillings_2 = 0, pennies_2 = 0,pounds_1 = 0, shillings_1 = 0, pennies_1 = 0;

    cout << "Enter the first amount in pounds : ";

    cin >> pounds_1;

    cout << "Enter the first amount in shillings : ";

    cin >> shillings_1;

    cout << "Enter the first amount in pennies : ";

    cin >> pennies_1;

    cout << "Enter the first amount in pounds : ";

    cin >> pounds_2;

    cout << "Enter the first amount in shillings : ";

    cin >> shillings_2;

    cout << "Enter the first amount in pennies : ";

    cin >> pennies_2;

    total_pounds = pounds_1 + pounds_2;

    total_shillings = shillings_1 + shillings_2;

    total_pennies = pennies_1 + pennies_2;

    if(total_pennies >= 12)

    {

      total_shillings += total_pennies/12;

      total_pennies = total_pennies%12;

    }

    if(total_shillings >= 20)

    {

      total_pounds += total_shillings/20;

      total_shillings = total_shillings%20;

    }

    cout << "Total : " << total_pounds << "." << total_shillings << "." << total_pennies << endl;

    cout << "Do you want to continue?(yes or no) : ";

    cin >> answer;

    if(answer == "no")

    {

      return 0;

    }

  }while(1);

}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS