In: Computer Science
a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms and grams. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. 1 pound (lb) is equal to 0.45359237 kilograms (kg). There are 1000 grams in a kilogram, and 16 ounces in a pound
#include<iostream>
using namespace std;
double getInput(){
double d;
cout<<"Enter weight in pounds: ";
cin>>d;
return d;
}
double convertToKg(double d){
return d * 0.45359237;
}
void display(double p,double k){
int kilos= (int)k;
int grams = (int)((k-kilos)*100);
cout<<p<<" pounds = "<<kilos<<" kilo and "<<grams<<" grams"<<endl;
}
int main(){
int ch=1;
double pounds,kgs;
do{
pounds = getInput();
kgs = convertToKg(pounds);
display(pounds,kgs);
cout<<"Press 1 to continue: ";
cin>>ch;
}while(ch==1);
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME