我正在一個小計算器,我不知道如何使用枚舉與開關/案例,所以我需要不使這個工作 我只需要掃描一個數字,比看到他枚舉 要不要參考意見什麼如何使用枚舉與決策開關語句
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define Pi 3.141592
int hypotri(void);
int disBePoints(void);
int circle(int y);
int square(void);
typedef enum calcOption
{
distance=1,
hypotenuse=2,
areaC=3,
areaR=4,
areaS=5
}option;
int main(void)
{
float finish=0, y=0,i=0;
printf("Welcome to my calculator!\n");
while(i!=6)
{
printf("Welcome to my calculator!\nchoose option:\n1 - Calc distance between 2 points\n2 - Calc hypotenuse of triangle\n3 - Calc area and perimeter of circle\n4 - Calc area of rectangle\n5 - Calc area of square\n6 - Exit");
scanf("%d",&option);
calcOption option;
option=calcOPtion(i);
switch(option)
{
case distance:
{
disBePoints();
("the distance is %f",finish);
break;
}
case hypotenuse:
{
hypotri();
("the hypotenuse is %f",finish);
break;
}
case areaC:
{
for(y=1;y>2;y++)
{
circle(y);
if(y=1)
{
("the perimeter is %f",finish);
}
else
{
("the area is %f",finish);
}
break;
}
}
case areaR:
{
square();
("the hypotenuse is %f",finish);
break;
}
case areaS:
{
square();
("the hypotenuse is %f",finish);
break;
}
default:
{
printf("dont mess with me enter number between 1-6");
}
}
}
system("pause");
return 0;
}
/** why= to see what is the distance between any points\n
input=none
output=none
**/
int disBePoints(void)
{
float xOne=0,xTwo=0,yOne=0,yTwo=0, finish=0;
printf("Enter point 1 coordinates:");
scanf("%f%f",&xOne,&yOne);
printf("\nEnter point 2 coordinates:");
scanf("%f%f",&xTwo,&yTwo);
finish=sqrt(pow(xTwo-xOne,2)+pow(yTwo-yOne,2));
return finish;
}
/** why= to see what is the hypotenuse of the triange
input=none
output=none
**/
int hypotri(void)
{
float x=0,y=0,finish;
printf("Enter 2 sides of the triangle:");
scanf("%f%f",&x,&y);
finish=sqrt(pow(x,2)+pow(y,2));
return finish;
}
/** why= to see what is primeter and the area of the circle
input=none
output=none
**/
int circle(int y)
{
float radius=0,finish=0;
printf("Enter circle radius:");
scanf("%f",&radius);
if(y=1)
{
finish=radius*2*Pi;
}
else
{
finish=pow(radius,2)*Pi;
}
return finish;
}
/** why= to see what is the area of the rectangle or the square
input=none
output=none
**/
int square(void)
{
float yside=0,xside=0,finish=0;
printf("Enter lentgh and width:");
scanf("%f%f",&xside,&yside);
finish=yside*xside;
return finish;
}
您將'option'定義爲*類型名稱*,它用作類型而不是變量。 –
在閱讀什麼使[mcve]之後提出一個問題? – sjsam
你應該更好地解釋一下問題所在。什麼不工作? – Zebrafish