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++
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);
© 2024 OneMinuteCode. All rights reserved.