View difference between Paste ID: aB0uHh5B and F40skHjt
SHOW: | | - or go back to the newest paste.
1
/* Homework 1 for Spring 2012 CS-1050
2
 * Aaron McRuer
3
 * Lab Section F
4
 * 2/18/2012
5
 * Version 1.0.0.0
6
 */
7
8
#include <stdio.h>
9
10-
int user_selection;
10+
11-
int type_selection;
11+
12-
double fahrenheit = 0;
12+
	int user_selection;
13-
double celsius = 0;
13+
	int type_selection;
14-
double print_temperature = 0;
14+
	float fahrenheit = 0;
15-
double miles = 0;
15+
	float celsius = 0;
16-
double kilometers = 0;
16+
	float print_temperature = 0;
17-
double print_distance = 0;
17+
	float miles = 0;
18-
double pounds = 0;
18+
	float kilometers = 0;
19-
double kilograms = 0;
19+
	float print_distance = 0;
20-
double print_weight = 0;
20+
	float pounds = 0;
21-
double square_mile = 0;
21+
	float kilograms = 0;
22-
double hectare = 0;
22+
	float print_weight = 0;
23-
double print_area = 0;
23+
	float square_mile = 0;
24-
double US_Dollar = 0;
24+
	float hectare = 0;
25-
double euro = 0;
25+
	float print_area = 0;
26-
double print_currency = 0;
26+
	float US_Dollar = 0;
27
	float euro = 0;
28
	float print_currency = 0;
29
30
	//welcome user and present menu options
31
	printf("Welcome to the Unit Conversion Tool. Please choose from the following options: \n");
32
	printf("	1. Temperature\n");
33
	printf("	2. Distance\n");
34
	printf("	3. Weight\n");
35
	printf("	4. Area\n");
36
	printf("	5. Currency\n");
37
	printf("	0. Exit\n");
38
	//take in user input for the menu
39
	scanf("%d", &user_selection);
40
	//loop until user types 0 for end-of-program
41-
	while (user_selection != EOF)
41+
	while (user_selection = 1||2||3||4||5)
42
	{
43
		//determine which option was selected
44
		switch (user_selection)
45
		{
46-
			case '1': //Temperature
46+
			case 1: //Temperature
47
						
48
			//present menu for what type of conversion they want
49
			printf("Select mode of conversion: \n");
50
			printf("	1. Fahrenheit to Celsius\n");
51
			printf("	2. Celsius to Fahrenheit\n");
52
			scanf("%d", &type_selection);
53
			
54
				//determine which option was selected	
55
				switch (type_selection)
56
				{
57-
					case '1':	//Fahrenheit to Celsius
57+
					case 1:	//Fahrenheit to Celsius
58
						printf("Please enter degrees Fahrenheit: \n");
59
						scanf("%f", &fahrenheit);
60
						print_temperature = (fahrenheit - 32) * (5/9);
61
						printf("%f degrees Fahrenheit = %f degrees Celsius\n", fahrenheit, print_temperature);
62
						break;
63-
					case '2':	//Celsius to Fahrenheit
63+
					case 2:	//Celsius to Fahrenheit
64
						printf("Please enter degrees Celsius: \n");
65
						scanf("%f", &celsius);
66
						print_temperature = (celsius * (9/5) + 32);
67
						printf("%f degrees Celsius = %f degrees Fahrenheit\n", celsius, print_temperature);
68
						break;
69
				}
70
				
71
				break;
72
73-
			case '2': //Distance
73+
			case 2: //Distance
74
			
75
			//present menu for what type of conversion they want
76
			printf("Select mode of conversion: \n");
77
			printf("	1. Miles to Kilometers\n");
78
			printf("	2. Kilometers to Miles\n");
79
			scanf("%d", &type_selection);
80
				
81
				//determine which option was selected
82
				switch (type_selection)
83
				{
84-
					case '1':	//Miles to Kilometers
84+
					case 1:	//Miles to Kilometers
85
						printf("Please enter the number of miles: \n");
86
						scanf("%f", &miles);
87
						print_distance = miles * 1.609344;
88
						printf("%f miles = %f kilometers\n", miles, print_distance);
89
						break;
90-
					case '2':	//Kilometers to Miles
90+
					case 2:	//Kilometers to Miles
91
						printf("Please enter the number of kilometers: \n");
92
						scanf("%f", &kilometers);
93
						print_distance = kilometers * 0.621371;
94
						printf("%f kilometers = %f miles\n", kilometers, print_distance);
95
						break;
96
				}	
97
				
98
				break;
99
100-
			case '3': //weight
100+
			case 3: //weight
101
			
102
			//present menu for what kind of conversion they want
103
			printf("Select mode of conversion: \n");
104
			printf("	1. Pounds to Kilograms\n");
105
			printf("	2. Kilograms to Pounds\n");
106
			scanf("%d", &type_selection);
107
			
108
				//determine which option was selected
109
				switch (type_selection)
110
				{
111-
					case '1':	//Pounds to Kilograms
111+
					case 1:	//Pounds to Kilograms
112
						printf("Please enter the number of pounds: \n");
113
						scanf("%f", &pounds);
114
						print_weight = pounds * 0.45359237;
115
						printf("%f pounds = %f kilograms\n", pounds, print_weight);
116
						break;
117-
					case '2':	//Kilograms to Pounds
117+
					case 2:	//Kilograms to Pounds
118
						printf("Please enter the number of kilograms: \n");
119
						scanf("%f", &kilograms);
120
						print_weight = kilograms * 2.20462262;
121
						printf("%f kilograms = %f pounds\n", kilograms, print_weight);
122
						break;
123
				}		
124
125
				break;
126
127-
			case '4': //area
127+
			case 4: //area
128
129
			//present menu for what kind of conversion they want
130
			printf("Select mode of conversion: \n");
131
			printf("	1. Square Mile to Hectare\n");
132
			printf("	2. Hectare to Square Mile\n");
133
			scanf("%d", &type_selection);
134
			
135
				//determine which option was selected
136
				switch (type_selection)
137
				{
138-
					case '1':	//Square Mile to Hectare
138+
					case 1:	//Square Mile to Hectare
139
						printf("Please enter the number of square miles: \n");
140
						scanf("%f", &square_mile);
141
						print_area = square_mile * 258.998811;
142
						printf("%f square miles = %f hectares\n", square_mile, print_area);
143
						break;
144-
					case '2':	//Hectare to Square Mile
144+
					case 2:	//Hectare to Square Mile
145
						printf("Please enter the number of hectares: \n");
146
						scanf("%f", &hectare);
147
						print_area = hectare * 0.00386102159;
148
						printf("%f hectares = %f square miles\n", hectare, print_area);
149
						break;
150
				}
151
			
152
				break;
153
154-
			case '5': //currency
154+
			case 5: //currency
155
			
156
			printf("Select mode of conversion: \n");
157
			printf("	1. US Dollar to EU Euro\n");
158
			printf("	2. EU Euro to US Dollar\n");
159
			scanf("%d", &type_selection);
160
161
				//determine which option was selected
162
				switch (type_selection)
163
				{
164-
					case '1':	//US Dollar to EU Euro
164+
					case 1:	//US Dollar to EU Euro
165
						printf("Please enter the number of US Dollars: \n");
166
						scanf("%f", &US_Dollar);
167
						print_currency = US_Dollar * 0.7599;
168
						printf("%f US Dollars = %f Euros\n", US_Dollar, print_currency);
169
						break;
170-
					case '2':	//Euro to Dollar
170+
					case 2:	//Euro to Dollar
171
						printf("Please enter the number of Euros: \n");
172
						scanf("%f, euro");
173
						print_currency = euro * 1.3159;
174
						printf("%f Euros = %f US Dollars", euro, print_currency);
175
						break;
176
				}
177
178
				break;
179
			
180
			
181
			
182
		}	
183
184
		
185
	}
186
}