In: Computer Science
2. Write a C++ program that;
Takes in the weight of a person in Kilograms, converts and outputs the equivalent weight in pounds. Format your output to 3 decimal places. Your output should look like this
53.000 Kg is equivalent to 123.459 Ibs
(Note 1Kg = 2.2046226218488 lbs)
Takes in the price of an item on an online store in pound sterling, converts and outputs the equivalent price in U.S dollars. Format your output to 2 decimal places.
Your output should look like this
£24.49 is equivalent to $31.96
To output the pound symbol, you need to display char(156). 156 signifies the pound notation's location on the ascii table shown in class
cout << char(156);
(Note £1 = $1.3048)
*BOTH CONVERSIONS SHOULD BE DONE IN THE SAME PROGRAM*
#include <iomanip>
#include<iostream>
using namespace std;
int main()
{
//declare variable
double kg_weight, lbs_weight, dollar_price,pound_price;
cout<<"Enter weight of a person in Kilograms: ";
//takes weight entered by user in kg_weight variable
cin>>kg_weight;
//converts kg to pounds
lbs_weight = kg_weight * 2.2046226218488;
//below 2 lines are used to format output to 3 decimal places
cout <<fixed;
cout <<setprecision(3);
cout<<kg_weight<< " Kg is equivalent to "<<lbs_weight<<" lbs"<<endl;
cout<<"Enter price of an item in pound sterling: ";
//takes price entered by user in pound_price variable
cin>>pound_price;
//converts pound to dollars
dollar_price = pound_price * 1.3048;
//below 2 lines are used to format output to 2 decimal places
cout <<fixed;
cout <<setprecision(2);
cout<<"£"<<pound_price<< " is equivalent to "<<char(36)<<dollar_price<<" lbs";
return 0;
}
OUTPUT: