c++ - Write a program that asks the user to enter a person's weight in kilograms (kg) and returns the equivalent weight in pounds (lbs) -
write program asks user enter person's weight in kilograms (kg) , returns equivalent weight in pounds (lbs). note 1 kg = 2.2 lbs. program should display 2 values (in kg , lb) rounded 2 decimal places (using header "iomanip" file).
#include <iostream> #include <iomanip> using namespace std; int main() { float p=0; cout << "enter le weight of personne in pounds : " << p << "\n"; cin >> p; cout << "the weight of personne : " << 2.2*p << "kg ou " << p << "pounds \n"; return 0; }
questions :
1- use library "iomanip" here? how else can do?
2- why program give me 0 on first line once run? wish write result on first line when program executed.
3- program seems comply statement?
do use library "iomanip" here? how else can do?
no not. need output io manipulator std::setw(2)
std::cout
before p
cout << "the weight of personne : " << setw(2) << p/2.2 << "kg ou " << p << "pounds \n";
why program give me 0 on first line once run? wish write result on first line when program executed.
because output p
std::cout
. change code to:
cout << "enter le weight of personne in pounds : "; cin >> p;
does program seems comply statement?
after fix it, should
Comments
Post a Comment