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
|
#include <iostream>
using namespace std;
// function protypes:
void introduction();
bool get_input(int& choice);
void get_output(int choice, double lengths, double weights, double& value);
double convert_lengths(int choice, double value, double lengths);
double convert_weights(int choice, double value, double weights);
int main()
{
int choice(1);
double value(0), lengths(0), weights(0);
introduction();
while (choice != 0)
{
if (get_input(choice))
get_output(choice, lengths, weights, value);
}
return 0;
}
void introduction()
{
cout << "Would you like to convert lengths or weights?" << endl;
cout << "Please enter 1 for lengths, 2 for weights," << endl;
cout << "and 0 if you wish to end the program" << endl;
}
bool get_input(int& choice)
{
cout << "Please enter your choice: ";
cin >> choice;
return choice != 0;
}
void get_output(int choice, double lengths, double weights, double& value)
{
switch (choice)
{
case 1:
value = convert_lengths(choice, value, lengths);
break;
case 2:
value = convert_weights(choice, value, weights);
break;
}
}
double convert_lengths(int choice, double value, double lengths)
{
return 1;
}
double convert_weights(int choice, double value, double weights)
{
return 2;
}
|