Hi all,
I just started to experiment with C, and i am trying to write a few rudimentary programs in order to get hands on with this language. I wrote a small prog to convert inches to cm or vice versa, however, when i am trying to get a choice from the user to select the type of conversion, the program is not working fine. Can someone point me out the error pls, as the prog compiles fine.
Code:
#include <stdio.h>
int main()
{
const float CMETERS = 2.54;
float input;
float ans;
char choice;
printf("1. Convert Inches to CM\n\n");
printf("2. Convert CM to Inches\n\n");
scanf("%c", &choice);
if (choice == '1')
{
printf("Enter the Amount of Inches ");
scanf("%f", &input);
ans = input * CMETERS;
printf("%f Inches are equal to %f", &input, &ans);
}
else if (choice == '2')
{
printf("Enter the Amount of Centimeters ");
scanf("%f", &input);
ans = input / CMETERS;
printf("%f CM are equal to %f", &input, &ans);
}
else
{
printf("Your selection %c is invalid", &choice);
}
system("PAUSE");
return 0;
}
Thank You