Calculate the user's weight in a second function. - C++ Function

C++ examples for Function:Function Creation

Description

Calculate the user's weight in a second function.

Demo Code

#include <iostream>
using namespace std;
int moon(int earth_weight);
int main()//from  w  w w  . j a  v a2 s. c  om
{
   int weight;    
   cout << "How many pounds do you weigh? ";
   cin >> weight;
   moon(weight);  
   return 0;      
}
int moon(int earth_weight)
{
   int moon_weight;   
   // Moon's weights are 1/6th of earth's weights.
   moon_weight = earth_weight / 6;
   cout << "You only weigh " << moon_weight << " pounds on the moon!";
   return 0;                      
}

Result


Related Tutorials