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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#include <iostream>
using namespace std;
double input_number(int feet, double inches)
{
cout << "please enter the number of feet" << endl;
cin >> feet;
cout << "please enter the number of inches" << endl;
cin >> inches;
return 1;
}
void do_conversion(int feet, double inches, double final_m, double final_cm)
{
final_m = feet * .3048;
final_cm = inches * 2.54;
}
double output_number(double final_m, double final_cm)
{
cout << "You values conver to:" << endl;
cout << final_m << "meters and" << final_cm << "cm." << endl;
cout << endl;
return 1;
}
double convert_lengths(double choice, double value, double lengths)
{
return 1;
}
double convert_weights(double choice, double value, double weights)
{
return 2;
}
double length_to_metric(double choice_2, double value_2, double metric, int feet, double inches)
{
cout << "You have choosen to convert ft/in. to m/cm." << endl;
metric = input_number(feet, inches);
return 1;
}
double length_to_us(double choice_2, double value_2, double us)
{
cout << "You have choosen to convert m/cm to ft/in.." << endl;
return 2;
}
double weight_to_metric(double choice_2, double value_2, double metric)
{
cout << "You have choosen to convert lbs/oz. to kg/g." << endl;
return 1;
}
double weight_to_us(double choice_2, double value_2, double metric)
{
cout << "You have choosen to convert kg/g to lbs/oz." << endl;
return 2;
}
void introduction()
{
cout << "This program converts lengths and weights." << endl;
cout << "Press 1 to convert lengths." << endl;
cout << "Press 2 to convert weights." << endl;
cout << "Press 0 to end the program." << endl;
}
void get_input(double& choice)
{
cout << endl;
cout << "What would you like to convert (length or weight)? Please enter your choice: ";
cin >> choice;
}
void get_output(double choice, double lengths, double weights, double& value, double choice_2,
double value_2, double metric, double us, int feet, double inches)
{
if(choice == 1)
{
value = convert_lengths(choice, value, lengths);
cout << "You choose lenghts." << endl;
cout << endl;
cout << "Would you like to convert ft./in. to m/cm? If so press 1" << endl;
cout << "If you would like to convert m/cm to ft./in.? if so press 2." << endl;
cout << "If you would like to stop converting length measurments press 0." << endl;
cout << "Enter:";
cin >> choice_2;
if(choice_2 == 1)
{
cout << "You pressed 1" << endl;
value_2 = length_to_metric(choice_2, value_2, metric, feet, inches);
}
if(choice_2 == 2)
{
cout << "You pressed 2" << endl;
value_2 = length_to_us(choice_2, value_2, metric);
}
}
if(choice == 2)
{
value = convert_weights(choice, value, weights);
cout << "You choose weights." << endl;
cout << endl;
cout << "Would you like to convert lbs/oz. to kg/g? If so press 1" << endl;
cout << "If you would like to convert kg/g to g/kg? if so press 2." << endl;
cout << "If you would like to stop converting weight measurments press 0." << endl;
cout << "Enter: ";
cin >> choice_2;
if(choice_2 == 1)
{
cout << "You pressed 1" << endl;
value_2 = weight_to_metric(choice_2, value_2, metric);
}
if(choice_2 == 2)
{
cout << "You pressed 2" << endl;
value_2 = weight_to_us(choice_2, value_2, us);
}
}
if(choice == 0)
{
cout << "Program Terminated." <<endl;
}
}
int main()
{
double choice(1), value(0), lengths(0), weights(0), choice_2(1), value_2(0), metric(0), us(0), feet(0), inches(0), final_m(0), final_cm(0);
introduction();
while (choice != 0 && choice_2 != 0)
{
get_input(choice);
get_output(choice, lengths, weights, value, choice_2, value_2, metric, us, feet, inches);
}
input_number(feet, inches);
do_conversion(feet, inches, final_m, final_cm);
output_number(final_m, final_cm);
return 0;
}
|