Conversion of Weight from Kg to Pound with use of Setprecision
Problem:
Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Solution:
# include <iostream> # include <iomanip> using namespace std; int main() { double weight; double poundWeight; cout<<"Enter the weight in kilogram"<<endl; cin>>weight; poundWeight=(weight*2.2); cout<<"The weight in kilograms is:"<<setprecision(2)<<fixed<<weight<<endl; cout<<"The weight in pounds is:"<<setprecision(2)<<poundWeight<<endl; return 0; }
Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Solution:
# include <iostream> # include <iomanip> using namespace std; int main() { double weight; double poundWeight; cout<<"Enter the weight in kilogram"<<endl; cin>>weight; poundWeight=(weight*2.2); cout<<"The weight in kilograms is:"<<setprecision(2)<<fixed<<weight<<endl; cout<<"The weight in pounds is:"<<setprecision(2)<<poundWeight<<endl; return 0; }
3 comments
Write commentsthe code doesn't it says that the statements are not statements because of the "<<"
ReplyNot me
ReplyNot me
Reply