1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
using namespace std;
void convertWeight(double ounces, double &grams, double pounds, double &kilograms);
double output(double ounces, double pounds);
int main()
{
double ounces;
double pounds;
char answer;
do
{
cout << "Enter weight in pounds and ounces: " << endl;
cin >> pounds >> ounces;
cout << output(pounds, ounces) << endl;
cout << "Do you want to test again (y/n)?: " << endl;
cin >> answer;
} while (answer == 'y' || answer == 'Y');
return 0;
}
double output(double ounces, double pounds)
{
double grams;
double kilograms;
convertWeight(ounces, grams, pounds, kilograms);
cout << pounds << " pounds and " << ounces << " ounces = "
<< kilograms << " kilograms and " << grams << " grams: " << endl;
return 0;
}
void convertWeight(double ounces, double &grams, double pounds, double &kilograms)
{
kilograms = (pounds + ounces / 1000000) / 2.20462;
grams = kilograms * 1000;
}
#include <iostream>
using namespace std;
void convertWeight(double grams, double &ounces, double kilograms, double £s);
double output(double grams, double kilograms);
int main()
{
double grams;
double kilograms;
char answer;
do
{
cout << "Enter weight in kilograms and grams: " << endl;
cin >> kilograms >> grams;
cout << output(kilograms, grams) << endl;
cout << "Do you want to test again (y/n)?: " << endl;
cin >> answer;
} while (answer == 'y' || answer == 'Y');
return 0;
}
double output(double grams, double kilograms)
{
double ounces;
double pounds;
convertWeight(grams, ounces, kilograms, pounds);
cout << kilograms << " kilograms and " << grams << " grams = "
<< pounds << " pounds and " << ounces << " ounces: " << endl;
return 0;
}
void convertWeight(double grams, double &ounces, double kilograms, double £s)
{
pounds = ( grams / 1000 + kilograms) / 0.453592 ;
ounces = pounds * 16;
}
|