How do I resolve the c6328 error that occurs here?

Asked 2 years ago, Updated 2 years ago, 34 views

int main(void) { int n; double x, y, z;

printf("1. Calculate triangle width 2. Calculate square width 3. Calculate trapezoidal width \n");
printf("Enter the number");
scanf("%d", &n);

switch (n)
{
case 1: printf("Please enter the length of the base :");
        scanf("%d", &x);
        printf("Please enter the length of the height :");
        scanf("%d", &y);
        printf("area of triangle: %lf", (x*y)/2);
        break;
case 2: printf("Please enter the length of the base :");
        scanf("%d", &x);
        printf("Please enter the length of the height :");
        scanf("%d", &y);
        printf("Square width: %lf", (x*y));
        break;
case 3: printf("Please enter the length of the base :");
        scanf("%d", &x);
        printf("Please enter the length of the height :");
        scanf("%d", &y);
        printf("Please enter the length of the upper side :");
        scanf("%d", &z);
        printf("Radish width: %lf", ((x+z)*y)/2);
        break;
}

}

There is a c6328 error in all scanf lines in the case statement, but I don't know how to fix the code.

c++

2022-09-20 11:06

1 Answers

Variables x, y, and z are double types. In the scanf function, the double type must be received with "%lf". Change all "%d" to "%lf" as shown below. For your information, "%d" is used to receive an int type.

scanf("%lf", &x);
scanf("%lf", &y);
scanf("%lf", &z);


2022-09-20 11:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.