Answer to Question #160988 in C++ for Ashes

Question #160988

Write a program to convert kilogram to grams by passing pointers as arguments to the

function. 


1
Expert's answer
2021-02-04T10:40:04-0500
#include <iostream>

void ConvertKilogramsToGrams(const double* kg, double* resultGrams)
{
    *resultGrams = *kg * 1000.0;
}

int main()
{
    std::cout << "Please enter value in kilograms: ";

    double kilograms;
    std::cin >> kilograms;

        if(!std::cin)
        {
            std::cout << "Bad input\n";
            return 1;
        }    

    double grams;
    ConvertKilogramsToGrams(&kilograms, &grams);

    std::cout << "Value in grams: " << grams << "\n";
    
    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

LATEST TUTORIALS
New on Blog