Answer to Question #163687 in C++ for Monissha

Question #163687

Write 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 in the

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


1
Expert's answer
2021-02-15T00:00:04-0500
#include <iostream>
using namespace std;

double kilo[4];

void get_input() {
    cout << "Enter 4 values in kilograms" << endl;
    for (int i = 0; i < 4; i++) {
        cin >> kilo[i];
    }
}

void convert_gram() {
    cout << "Converted values from kilograms to grams" << endl;
    for (int i = 0; i < 4; i++) {
        cout << "element_" << i << " = " << kilo[i] * 1000.0 << "g" << endl;
    }
}

void convert_pound() {
    cout << "Converted values from kilograms to pounds" << endl;
    for (int i = 0; i < 4; i++) {
        cout << "element_" << i << " = " << kilo[i] * 2.205 << "pounds" << endl;
    }
}

int main() {
    get_input();
    convert_gram();
    convert_pound();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment