OK, so I wrote the program the way Elysia suggested, and it works great. Now, after the number is converted, i want to ask the user if they want to convert another value. If they type 'y' or 'Y', it prompts them again. 'n' or 'N' ends the program. Any suggestions are welcome, thanks. Here is my code:
Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main()
{
double num1, meters, feet, kilos, pounds, liters, gallons, kms, miles;
int option;
cout << "Please select the conversion type you want to perform:" << endl;
cout << "1. Convert feet to meters" << endl;
cout << "2. Convert meters to feet" << endl;
cout << "3. Convert lbs. to kilograms" << endl;
cout << "4. Convert kilograms to lbs." << endl;
cout << "5. Convert gallons to liters" << endl;
cout << "6. Convert liters to gallons" << endl;
cout << "7. Convert square miles to square kilometers" << endl;
cout << "8. Convert square kilometers to square miles" << endl << endl;
cin >> option;
switch(option)
{
case 1:
cout << endl << "Enter the number of feet to convert to meters:" << endl;
cin >> num1;
meters = num1 * 0.3048;
cout << num1 << " feet is equal to " << meters << " meters." << endl;
break;
case 2:
cout << endl << "Enter the number of meters to convert to feet:" << endl;
cin >> num1;
feet = num1 * 3.2808399;
cout << num1 << " meters is equal to " << feet << " feet." << endl;
break;
case 3:
cout << endl << "Enter the number of pounds to convert to kilograms:" << endl;
cin >> num1;
kilos = num1 * 0.45359237;
cout << num1 << " lbs. is equal to " << kilos << " kilograms." << endl;
break;
case 4:
cout << endl << "Enter the number of kilograms to convert to pounds:" << endl;
cin >> num1;
pounds = num1 * 2.20462262;
cout << num1 << " kilograms is equal to " << pounds << " lbs." << endl;
break;
case 5:
cout << endl << "Enter the number of gallons to convert to liters:" << endl;
cin >> num1;
liters = num1 * 3.7854118;
cout << num1 << " gallons is equal to " << liters << " liters." << endl;
break;
case 6:
cout << endl << "Enter the number of liters to convert to gallons:" << endl;
cin >> num1;
gallons = num1 * 0.264172051;
cout << num1 << " liters is equal to " << gallons << " gallons." << endl;
break;
case 7:
cout << endl << "Enter the number of square miles to convert into square kilometers:" << endl;
cin >> num1;
kms = num1 * 2.58998811;
cout << num1 << " square miles is equal to " << kms << " square kilometers." << endl;
break;
case 8:
cout << endl << "Enter the number of square kilometers to convert into square miles:" << endl;
cin >> num1;
miles = num1 * 0.386102159;
cout << num1 << " square kilometers is equal to " << miles << " square miles." << endl;
break;
default:
break;
}
return 0;
}