当我运行代码时,我的开关情况不起作用,当我输入1时,它不打印情况1,等等,我尝试了每件事,但没有工作,有人能帮助我吗?当我运行代码时,我的开关情况不起作用,当我输入1时,它不打印情况1,等等,我尝试了每件事,但没有工作,有人能帮助我吗?
#include <stdio.h>
#include <math.h>
int main ()
{
int choice;
float area;
printf("1 for area of Square\n");
printf(" 2 for area of Circle\n");
printf(" 3 for finding area of rectangle\n");
switch(choice) {
case 1: {
float side,area;
printf("Enter Sides of Square");
scanf("%f",&side);
area=(float)side*side;
printf("Area of Square is %f",area);
break;
}
case 2: {
float radius,area;
printf("Enter Radius of Circle");
scanf("%f",&radius);
area=(float)3.14159*radius*radius;
printf("Area of Circle %f",area);
break;
}
case 3: {
float len,breadth,area;
printf("Enter Length and Breadth of Rectangle");
scanf("%f %f",&len,&breadth);
area=(float)len*breadth;
printf("Area of Rectangle is %f",area);
break;
}
default: {
printf("Invalid Choice");
break;
}
}
return 0;**strong text**
}
1条答案
按热度按时间kognpnkq1#
您缺少用户输入。我已经在行下面添加了
scanf
,它现在可以工作了代码完整版本
输出量: