C++ program to convert grams to kilograms

Views: 930   

Following program shows you how to convert grams to kilograms.
In this program we get grams from user, once we get those we need to divide with 1000 so that we get in kilograms

#include <iostream>
#include <math.h>

int main() {
    float grams;
    std::cout << "Please enter grams:";
    std::cin >> grams;
    float kilograms = grams / 1000;
    std::cout << kilograms << " Kilograms";


Please enter grams: 1000
1 Kilograms
On By