Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Homework 1 for Spring 2012 CS-1050
- * Aaron McRuer
- * Lab Section F
- * 2/18/2012
- * Version 1.0.0.0
- */
- #include <stdio.h>
- int main(void)
- {
- int user_selection;
- int type_selection;
- float fahrenheit = 0;
- float celsius = 0;
- float print_temperature = 0;
- float miles = 0;
- float kilometers = 0;
- float print_distance = 0;
- float pounds = 0;
- float kilograms = 0;
- float print_weight = 0;
- float square_mile = 0;
- float hectare = 0;
- float print_area = 0;
- float US_Dollar = 0;
- float euro = 0;
- float print_currency = 0;
- //welcome user and present menu options
- printf("Welcome to the Unit Conversion Tool. Please choose from the following options: \n");
- printf(" 1. Temperature\n");
- printf(" 2. Distance\n");
- printf(" 3. Weight\n");
- printf(" 4. Area\n");
- printf(" 5. Currency\n");
- printf(" 0. Exit\n");
- //take in user input for the menu
- scanf("%d", &user_selection);
- //loop until user types 0 for end-of-program
- while (user_selection = 1||2||3||4||5)
- {
- //determine which option was selected
- switch (user_selection)
- {
- case 1: //Temperature
- //present menu for what type of conversion they want
- printf("Select mode of conversion: \n");
- printf(" 1. Fahrenheit to Celsius\n");
- printf(" 2. Celsius to Fahrenheit\n");
- scanf("%d", &type_selection);
- //determine which option was selected
- switch (type_selection)
- {
- case 1: //Fahrenheit to Celsius
- printf("Please enter degrees Fahrenheit: \n");
- scanf("%f", &fahrenheit);
- print_temperature = (fahrenheit - 32) * (5/9);
- printf("%f degrees Fahrenheit = %f degrees Celsius\n", fahrenheit, print_temperature);
- break;
- case 2: //Celsius to Fahrenheit
- printf("Please enter degrees Celsius: \n");
- scanf("%f", &celsius);
- print_temperature = (celsius * (9/5) + 32);
- printf("%f degrees Celsius = %f degrees Fahrenheit\n", celsius, print_temperature);
- break;
- }
- break;
- case 2: //Distance
- //present menu for what type of conversion they want
- printf("Select mode of conversion: \n");
- printf(" 1. Miles to Kilometers\n");
- printf(" 2. Kilometers to Miles\n");
- scanf("%d", &type_selection);
- //determine which option was selected
- switch (type_selection)
- {
- case 1: //Miles to Kilometers
- printf("Please enter the number of miles: \n");
- scanf("%f", &miles);
- print_distance = miles * 1.609344;
- printf("%f miles = %f kilometers\n", miles, print_distance);
- break;
- case 2: //Kilometers to Miles
- printf("Please enter the number of kilometers: \n");
- scanf("%f", &kilometers);
- print_distance = kilometers * 0.621371;
- printf("%f kilometers = %f miles\n", kilometers, print_distance);
- break;
- }
- break;
- case 3: //weight
- //present menu for what kind of conversion they want
- printf("Select mode of conversion: \n");
- printf(" 1. Pounds to Kilograms\n");
- printf(" 2. Kilograms to Pounds\n");
- scanf("%d", &type_selection);
- //determine which option was selected
- switch (type_selection)
- {
- case 1: //Pounds to Kilograms
- printf("Please enter the number of pounds: \n");
- scanf("%f", £s);
- print_weight = pounds * 0.45359237;
- printf("%f pounds = %f kilograms\n", pounds, print_weight);
- break;
- case 2: //Kilograms to Pounds
- printf("Please enter the number of kilograms: \n");
- scanf("%f", &kilograms);
- print_weight = kilograms * 2.20462262;
- printf("%f kilograms = %f pounds\n", kilograms, print_weight);
- break;
- }
- break;
- case 4: //area
- //present menu for what kind of conversion they want
- printf("Select mode of conversion: \n");
- printf(" 1. Square Mile to Hectare\n");
- printf(" 2. Hectare to Square Mile\n");
- scanf("%d", &type_selection);
- //determine which option was selected
- switch (type_selection)
- {
- case 1: //Square Mile to Hectare
- printf("Please enter the number of square miles: \n");
- scanf("%f", &square_mile);
- print_area = square_mile * 258.998811;
- printf("%f square miles = %f hectares\n", square_mile, print_area);
- break;
- case 2: //Hectare to Square Mile
- printf("Please enter the number of hectares: \n");
- scanf("%f", &hectare);
- print_area = hectare * 0.00386102159;
- printf("%f hectares = %f square miles\n", hectare, print_area);
- break;
- }
- break;
- case 5: //currency
- printf("Select mode of conversion: \n");
- printf(" 1. US Dollar to EU Euro\n");
- printf(" 2. EU Euro to US Dollar\n");
- scanf("%d", &type_selection);
- //determine which option was selected
- switch (type_selection)
- {
- case 1: //US Dollar to EU Euro
- printf("Please enter the number of US Dollars: \n");
- scanf("%f", &US_Dollar);
- print_currency = US_Dollar * 0.7599;
- printf("%f US Dollars = %f Euros\n", US_Dollar, print_currency);
- break;
- case 2: //Euro to Dollar
- printf("Please enter the number of Euros: \n");
- scanf("%f, euro");
- print_currency = euro * 1.3159;
- printf("%f Euros = %f US Dollars", euro, print_currency);
- break;
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement