Hi I'm writting this post because this program I wrote hangs in it's while() after the user input I'm including the program code and I can't figure out why it hangs. I think the error might also could be with scanf(), I've included the code any help would be greatly apprecaited.Code:/***************************************************************************************/ /* Metric.C - Converts English length units to their metric equivalent */ #include <stdio.h> char line[100]; /* line of input data */ char unit_type[1000]; /* the type of unit you want it converted from */ double english; /* the number of english units to be converted */ double result; /* the result of the conversion */ double inches; double feet; double yards; double miles; int main() { printf("Please enter the number of you units you want converted and their unit type in the format units then unit type,\n"); printf("possible conversion types are: inches to centimeters, feet to meters, yards to meters, miles to kilometers.\n"); printf("Please enter the number of units to be converted followed by their type or type q to quit: "); fgets(line, sizeof(line), stdin); scanf(line,"%lf %s", &english, &unit_type); while (1) { if (unit_type == "q") break; if (unit_type == "inches") { result = english * 2.54; printf("The number of centimeters are %lf\n", result); } else if (unit_type == "feet") { result = english * 0.3048; printf("The number of meters are %lf\n", result); } else if (unit_type == "yards") { result = english * 0.9144; printf("The number of meters are %lf\n", result); } else if (unit_type == "miles") { printf("The number of kilometers are %lf\n", result); result = english * 1.609347; } } return (0); }



LinkBack URL
About LinkBacks



