
Fantasy F.
asked 01/27/21Write a program to convert kilogram to gram and pound
Declare an array as a global variable, called kilo with 4 elements.
- In main():
Call function get_input().
Call function convert_gram().
Call function convert_pound().
- In get_input():
Using for loop, prompt the user to input the values in kilogram and store them inthe array kilo.
- In convert_gram():
Use for loop to convert the values in grams and display the values.
Formula: 1 kg = 1000 g
- In convert_pound():
Use for loop to convert the values in pounds and display the values.
Formula: 1 kg = 2.205 pounds
Sample Output
Enter the value in Kilogram
3.5
6.75
0.45
2.1
Convert Kilo to Gram
3.50 is equal to 3500.00 grams
6.75 is equal to 6750.00 grams
0.45 is equal to 450.00 grams
2.10 is equal to 2100.00 grams
Covert Kilo to Pound
3.50 is equal to 7.72 pound
6.75 is equal to 14.88 pound
0.45 is equal to 0.99 pound
2.10 is equal to 4.63 pound
1 Expert Answer

Patrick B. answered 01/27/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <iomanip>
#define nMax (4)
#define POUNDS_PER_KG (2.205)
int get_input(float * kilo)
{
for (int iLoop=0; iLoop<nMax; iLoop++)
{
cout << " Enter the weight value in kilograms :>";
cin >> kilo[iLoop];
}
}
int convert_gram(float * kilo, float * grams)
{
for (int iLoop=0; iLoop<nMax; iLoop++)
{
grams[iLoop] = kilo[iLoop]*1000;
}
}
int convert_pound(float * kilo, float * pounds)
{
for (int iLoop=0; iLoop<nMax; iLoop++)
{
pounds[iLoop] = kilo[iLoop]*POUNDS_PER_KG;
}
}
int Go()
{
float kilo[nMax];
float grams[nMax];
float pounds[nMax];
get_input(kilo);
convert_gram(kilo,grams);
convert_pound(kilo,pounds);
cout << fixed;
cout << "Kilograms" << endl;
for (int iLoop=0; iLoop<nMax; iLoop++)
{
cout << setprecision(2) << kilo[iLoop] << endl;
}
cout << endl << endl << "Convert Kilo to Gram" << endl;
for (int iLoop=0; iLoop<nMax; iLoop++)
{
cout << setprecision(2)<< kilo[iLoop] << " kg = " << setprecision(2) << grams[iLoop] << " grams " << endl;
}
cout << endl << endl << "Convert Kilo to Pound" << endl;
for (int iLoop=0; iLoop<nMax; iLoop++)
{
cout << setprecision(2) << kilo[iLoop] << " kg = " << setprecision(2) << pounds[iLoop] << " pounds " << endl;
}
cout << endl << endl << endl<< " table " << endl << endl;
cout << " kg grams pounds " << endl;
cout << "----------------------------------" << endl;
for (int iLoop=0; iLoop<nMax; iLoop++)
{
cout << " " << setprecision(2)<< kilo[iLoop] << " " << setprecision(2)<< grams[iLoop] << " " << setprecision(2)<< pounds[iLoop] << endl;
}
}
int main()
{
Go();
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code uploaded to RESOURCES section under this link01/27/21