실제 입력 int를 double로 변환하는 방법이 있습니까? 문자열 값을 가져 오지 않고 isDigit을 사용하여 double인지 int인지 확인합니다.int에서 double로 입력 변환
int main(void)
{
// Initializing variables
int a,b,c,res;
// Getting input from user
printf("Please enter the sides of triangle");
printf("\nPlease enter side 1:");
scanf("%d",&a);
printf("Please enter side 2:");
scanf("%d",&b);
printf("Please enter side 3:");
scanf("%d",&c);
// Calling function in order to print type of the triangle.
checkTriangle(a,b,c);
}
// A function which decides the type of the triangle and print it
void checkTriangle(int s1, int s2,int s3)
{
// Check the values whether it is triangle or not.
if ((s1 + s2 > s3 && s1 + s3 > s2 && s2 + s3 > s1) && (s1 > 0 && s2 > 0 && s3 > 0))
{
// Deciding type of triangle according to given input.
if (s1 == s2 && s2 == s3)
printf("EQUILATERAL TRIANGLE");
else if (s1 == s2 || s2 == s3 || s1 == s3)
printf("ISOSCELES TRIANGLE\n");
else
printf("SCALENE TRIANGLE \n");
}
else
printf("Triangle could not be formed.");
}
사용자가 double을 입력 할 때 내가 원하는 것은 double을 입력 할 수 있다는 메시지를 전하고 싶습니다. 문자 입력을하지 않고도 그렇게 할 수 있습니까?
이 입력은 어디에서 오는가? 너 뭐하려고? – epsalon
사용자가 double input을 입력하면 int로 변환됩니다. 이걸 어떻게 막을 수 있습니까? – snnlankrdsm
@MertMetin, 아마도 int를 기대하고 있기 때문에 그것은 숫자가 아니기 때문에 십진수에서 멈 춥니 다. – chris