int main(int argc, const char * argv[])
{
char userInput;
int centimeter;
int meter;
float centimeterFloat = 0.0;
float meterFloat = 0.0;
printf("Enter c for centimeter to meter OR m for meter to centimeter: ");
userInput = getchar();
//If the user types in 'm' or 'M' the progrsm will ask you to type in the length in meters and it will converts to centimeters.
if (userInput == 'M')
userInput = 'm';
if (userInput == 'm')
{
//This calculation is to convert meters to centimeters.
printf("\nEnter the length in meter: ");
scanf("%d", &meter);
centimeterFloat
= (meter * 100);
printf("\nmeter\tcentimeter\n");
printf("%d\t\t\t%4.0f\n", meter, centimeterFloat);
}
//If the user types in 'c' or 'C' the program will ask you to type in the length in centimeters and it will converts to meters.
if (userInput == 'C')
userInput = 'c';
else if (userInput == 'c')
{
printf("\nEnter the length in centimeter: ");
scanf("%d", ¢imeter);
//This calculation is to convert centimeters to meters.
meterFloat = (centimeter * 1/100);
printf("\nmeter\tcentimeter\n");
printf("%3.1f\t\t\t%d\n", meterFloat, centimeter);
}
return 0;
}
これは私のコードですが、入力を 10 進数として入力すると、出力が適切に出力されません。助けてください。 if else ステートメントでプログラムしますか? 助けてくださいどうもありがとう