在C中选择三个选项(多个选项)

时间:2015-07-27 12:51:50

标签: c++ c if-statement math

您好我正在研究计算器,我可以选择要解决的问题。首先,你会被问到你有多少。对于这段代码,我刚给出了3个。因此,默认情况下,输入3.接下来,我有一个11的列表给出,以解决所有方程。用户将从1-11中选择3个数字...我已经使用数字1,3,9和1,3,10以及1,3,11开始了一个案例。所以我的问题是,当我随机选择1,3,10时,例如我通过选择3,10,1而不是1,3,10来改变我在输入中的顺序,选择2,选择3 ...... / p>

所以我想说我会选择1,3,10但是我按照这个顺序输入了它... 10,3,1 ..但仍然必须去实施它将要实施的动作。

我在if语句中使用了以下行... if(选择== 1,3,10& choice2 == 1,3,10& 7 choice3 == 1,3,10)然后执行行动......

if((choice == 1 || 3 || 10)&&(choice2 == 1 || 3 || 10)&&(choice3 == 1 || 3 || 10))然后执行行动...

我已尝试过上述内容,但它不会执行下面的语句......但它会执行上面的语句......

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.14159265

int main(){

double length, angle, radius, tangent, chord, midordinate, external, degree;
double pcurve,ptan,pintersect;
double ulength, udegree, uangle, uradius, utangent, uchord, umidordinate, uexternal;
int choice, choice2, choice3, given;

//For sin, cos, tan
double x, ret, val;
val = PI / 180;

printf("Enter number of given: ");
scanf("%d",&given);

if(given==3){
        choice:
        printf("[1]   -  Angle\n");
        printf("[2]   -  Degree\n");

        printf("[3]   -  Radius\n");
        printf("[4]   -  Length of Curve\n");           
        printf("[5]   -  Tangent\n");
        printf("[6]   -  Chord\n");
        printf("[7]   -  Midordinate\n");
        printf("[8]   -  External Distance\n");

        printf("[9]   -  Point of Intersection\n");
        printf("[10]  -  Point of Curve\n");
        printf("[11]  -  Point of Tangent\n");

printf("\n");

printf("Enter 1st given: ");
scanf("%d",&choice);

printf("Enter 2nd given: ");
scanf("%d",&choice2);   

printf("Enter 3rd given: ");
scanf("%d",&choice3);

printf("\n-----------------------------------\n");

if(choice==1,3,9 && choice2==1,3,9 && choice3==1,3,9){
        printf("Enter angle: ");
        scanf("%lf",&angle);

        printf("Enter radius: ");
        scanf("%lf",&radius);

        printf("Enter Point of Intersection (Point of Curve Value): ");
        scanf("%lf",&pcurve);

        printf("Enter Point of Intersection (Tangent Value): ");
        scanf("%lf",&tangent);

        printf("-----------------------------------\n");
        printf("\nGIVEN:\n");
        printf("-----------------------------------\n");
        printf("Angle = %lf\n",angle);
        printf("Radius = %lf\n",radius);
        printf("Point of Intersection (PI) = %lf + %lf\n", pcurve,tangent);

        uangle = angle/2;

        printf("-----------------------------------\n");
        printf("\nRESULTS:\n");
        printf("-----------------------------------\n");
        length=(radius*angle*PI)/180;
        tangent = radius * (tan(uangle*val));
        chord = 2*radius*(sin(uangle*val)); 
        midordinate = radius - (radius*(cos(uangle*val)));
        external = radius *( (1/(cos (uangle*val) ) ) - 1 ) ;   
        pintersect = pcurve + tangent;
        pcurve = pintersect - tangent;
        ptan = pcurve + length;

        printf("Radius = %lf\n",radius);
        printf("Length of Curve = %lf\n",length);
        printf("Tangent = %lf\n",tangent);
        printf("Chord = %lf\n",chord);
        printf("Mid Ordinate = %lf\n",midordinate);
        printf("External Distance = %lf\n",external);
        printf("Point of Intersection = %lf\n",pintersect);
        printf("Point of Curve = %lf\n",pcurve);
        printf("Point of Tangent = %lf\n",ptan);

}

else

if( (choice== 1 || 3 || 10) && (choice2== 1 || 3 || 10) && (choice3== 1 || 3 || 10)){
        printf("Enter angle: ");
        scanf("%lf",&angle);

        printf("Enter radius: ");
        scanf("%lf",&radius);

        printf("Enter Point of Curve (Point of Intersection Value): ");
        scanf("%lf",&pintersect);

        printf("Enter Point of Curve (Tangent Value): ");
        scanf("%lf",&tangent);

        printf("-----------------------------------\n");
        printf("\nGIVEN:\n");
        printf("-----------------------------------\n");
        printf("Angle = %lf\n",angle);
        printf("Radius = %lf\n",radius);
        printf("Point of Curve (PC) = %lf - %lf\n", pintersect,tangent);

        uangle = angle/2;

        printf("-----------------------------------\n");
        printf("\nRESULTS:\n");
        printf("-----------------------------------\n");
        length=(radius*angle*PI)/180;
        tangent = radius * (tan(uangle*val));
        chord = 2*radius*(sin(uangle*val)); 
        midordinate = radius - (radius*(cos(uangle*val)));
        external = radius *( (1/(cos (uangle*val) ) ) - 1 ) ;   
        pintersect = pcurve + tangent;
        pcurve = pintersect - tangent;
        ptan = pcurve + length;

        printf("Radius = %lf\n",radius);
        printf("Length of Curve = %lf\n",length);
        printf("Tangent = %lf\n",tangent);
        printf("Chord = %lf\n",chord);
        printf("Mid Ordinate = %lf\n",midordinate);
        printf("External Distance = %lf\n",external);
        printf("Point of Intersection = %lf\n",pintersect);
        printf("Point of Curve = %lf\n",pcurve);
        printf("Point of Tangent = %lf\n",ptan);

}

if(choice==1,3,11 && choice2==1,3,11 && choice3==1,3,11){
        printf("Enter angle: ");
        scanf("%lf",&angle);

        printf("Enter radius: ");
        scanf("%lf",&radius);

        printf("Enter Point of Tangent (Point of Curve Value): ");
        scanf("%lf",&pintersect);

        printf("Enter Point of Tangent (Length Value): ");
        scanf("%lf",&length);

        printf("-----------------------------------\n");
        printf("\nGIVEN:\n");
        printf("-----------------------------------\n");
        printf("Angle = %lf\n",angle);
        printf("Radius = %lf\n",radius);
        printf("Point of Curve (PC) = %lf + %lf\n", pcurve,length);

        uangle = angle/2;

        printf("-----------------------------------\n");
        printf("\nRESULTS:\n");
        printf("-----------------------------------\n");
        length=(radius*angle*PI)/180;
        tangent = radius * (tan(uangle*val));
        chord = 2*radius*(sin(uangle*val)); 
        midordinate = radius - (radius*(cos(uangle*val)));
        external = radius *( (1/(cos (uangle*val) ) ) - 1 ) ;   
        pintersect = pcurve + tangent;
        pcurve = pintersect - tangent;
        ptan = pcurve + length;

        printf("Radius = %lf\n",radius);
        printf("Length of Curve = %lf\n",length);
        printf("Tangent = %lf\n",tangent);
        printf("Chord = %lf\n",chord);
        printf("Mid Ordinate = %lf\n",midordinate);
        printf("External Distance = %lf\n",external);
        printf("Point of Intersection = %lf\n",pintersect);
        printf("Point of Curve = %lf\n",pcurve);
        printf("Point of Tangent = %lf\n",ptan);

}




}


getch();
return 0;
}

1 个答案:

答案 0 :(得分:1)

if(choice==1,3,9 && choice2==1,3,9 && choice3==1,3,9){

if( (choice== 1 || 3 || 10) && (choice2== 1 || 3 || 10) && (choice3== 1 || 3 || 10))  //always TRUE

if(choice==1,3,11 && choice2==1,3,11 && choice3==1,3,11){

您是否认为这些条件是符合您需求的有效语法?

正确

if((choice==1 ||choice==3 ||choice==9) && (choice2==1 ||choice2==3 ||choice2==9) && (choice3==1 ||choice3==3 ||choice3==9))

if((choice==1 ||choice==3 ||choice==10) && (choice2==1 ||choice2==3 ||choice2==10) && (choice3==1 ||choice3==3 ||choice3==10))

if((choice==1 ||choice==3 ||choice==11) && (choice2==1 ||choice2==3 ||choice2==11) && (choice3==1 ||choice3==3 ||choice3==11))