Created
January 26, 2017 13:53
-
-
Save dave-martinez/2280d415a776a16d0a02f5072dc567e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
main() | |
{ | |
printf("Units converter:\n\n"); | |
printf("[k] Kilogram (kg)\n[p] Pounds (lbs)\n[o] Ounces(o)\n"); | |
char firstUnit = ' '; | |
char secondUnit = ' '; | |
float initialValue, convertedValue; | |
printf("Select unit initial: "); | |
scanf("%c", &firstUnit); | |
printf("Select unit final: "); | |
scanf(" %c", &secondUnit); | |
printf("Enter value: "); | |
scanf("%f", &initialValue); | |
switch(firstUnit) | |
{ | |
case 'k': | |
switch(secondUnit) | |
{ | |
case 'k': convertedValue = initialValue; break; | |
case 'p': convertedValue = initialValue * 2.20462; break; | |
case 'o': convertedValue = initialValue * 35.274; break; | |
default: printf("Invalid option selected. Re-run the program.");break; | |
} | |
break; | |
case 'p': | |
switch(secondUnit) | |
{ | |
case 'k': convertedValue = initialValue * 0.453592; break; | |
case 'p': convertedValue = initialValue; break; | |
case 'o': convertedValue = initialValue * 16; break; | |
default: printf("Invalid option selected. Re-run the program.");break; | |
} | |
break; | |
case 'o': | |
switch(secondUnit) | |
{ | |
case 'k': convertedValue = initialValue * 0.0283495; break; | |
case 'p': convertedValue = initialValue * 0.0625; break; | |
case 'o': convertedValue = initialValue; break; | |
default: printf("Invalid option selected. Re-run the program.");break; | |
} | |
break; | |
default: printf("Invalid option selected. Re-run the program.");break; | |
} | |
printf("Result: %f",convertedValue); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment