I am practising the if code and decided to do a converter of different units of different types. It is not finished yet but I am running into a problem, when I select 2 then 9, 10, 11,12 it always starts with 8. It reads off 8 then goes 9... Help will be appreciated. Here is the code ...
Code:
#include <stdio.h>
#include <conio.h>
int main(void)
{
int Type_of_conversion;
float fahrenheit;
float celsius;
int f_or_c;
printf("Temperature......................1\n\n");
printf("Mass.............................2\n\n");
printf("Type The Corresponding Number To Select The Type of Conversion: ");
scanf("%d" ,&Type_of_conversion);
if (Type_of_conversion ==1)
{
printf("\n");
printf("Fahrenheit to Celsius.......1\n");
printf("Celsius to Fahrenheit.......2\n");
printf("\n");
printf("Type the corresponding number for the unit of conversion: ");
scanf("%d" ,&f_or_c);
if (f_or_c == 1) {
printf("Enter the Temperature in Fahrenheit: ");
scanf("%f" ,&fahrenheit);
celsius = (fahrenheit-32)*(5.0/9.0);
printf("%f degrees celsius", celsius);
}
if (f_or_c == 2) {
printf("Enter the Temperature in Celsius: ");
scanf("%f" ,&celsius);
fahrenheit = celsius*(9.0/5.0) + 32;
printf("%f degress fahrenheit", fahrenheit);
}
}
if (Type_of_conversion ==2) {
printf(" \n");
printf("Kilograms to Pounds.........1\n");
printf("Pounds to Kilograms.........2\n");
printf("Kilograms to Ounces.........3\n");
printf("Ounces to Kilograms.........4\n");
printf("Pounds to Ounces............5\n");
printf("Ounces to Pounds............6\n");
printf("Grams to Kilograms..........7\n");
printf("Kilograms to Grams..........8\n");
printf("Grams to Pounds.............9\n");
printf("Pounds to Grams.............10\n");
printf("Grams to Ounces.............11\n");
printf("Ounces to Grams.............12\n");
printf(" \n");
printf("Type the corresponding number for the unit of conversion: ");
int type_of_mass;
float kg;
float pound;
float grams;
float ounce;
scanf("%d" ,&type_of_mass);
if (type_of_mass ==1){
printf("Enter the mass in Kilograms: ");
scanf("%f" ,&kg);
pound = (kg*2.2);
printf("%f Pounds" ,pound);
}
if (type_of_mass ==2) {
printf("Enter the mass in Pounds: ");
scanf("%f" ,£);
kg = (pound*0.4535);
printf("%f Kilograms" ,kg);
}
if (type_of_mass ==3) {
printf("Enter the mass in Kilograms: ");
scanf("%f" ,&kg);
ounce = kg*35.274;
printf("%f Ounces" ,ounce);
}
if (type_of_mass ==4){
printf("Enter the mass in Ounces: ");
scanf("%f" ,&ounce);
kg = ounce*(1.0/35.274);
printf("%f Kilograms" ,kg);
}
if (type_of_mass ==5) {
printf("Enter the mass in Pounds: ");
scanf("%f" ,£);
ounce = pound*16;
printf("%f Ounces" ,ounce);
}
if (type_of_mass ==6) {
printf("Enter the mass in Ounces: ");
scanf("%f" ,&ounce);
pound = ounce/16;
printf("%f Pounds" ,pound);
}
if (type_of_mass ==7) {
printf("Enter the mass in Grams: ");
scanf("%f" ,&grams);
kg = grams/1000;
printf("%f Kilograms" ,kg);
}
if (type_of_mass ==8); {
printf("Enter the mass in Kilograms: ");
scanf("%f" ,&kg);
grams = (kg*1000);
printf("%f Grams" ,grams);
}
if (type_of_mass ==9) {
printf("Enter the mass in Grams: ");
scanf("%f" ,&grams);
pound = grams*0.0022;
printf("%f Pounds" ,pound);
}
if (type_of_mass ==10) {
printf("Enter the mass in Pounds: ");
scanf("%f" ,£);
grams = pound/0.0022046;
printf("%f Grams" ,grams);
}
}
getchar();
return 0;
}