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

Select three choices (multiple choices) in C

本文关键字:三个 选项 多选 选择      更新时间:2023-10-16

嗨,我正在做一个计算器,我可以选择解决什么问题。首先,你会被问到你有多少。对于这段代码,我让3给定。默认情况下,输入3。接下来,我列出了11个用来解所有方程的列表。用户将从1-11中选择3个数字…我用数字1,3,9和1,3,10和1,3,11开始了一个案例。所以我的问题是,当我随机选择1,3,10时,例如,我改变了选项,选择2,选择3的输入顺序通过选择3,10,1而不是1,3,10…

假设我要选择1,3,10但我是按这个顺序输入的…10、3、1 . .但仍然必须付诸行动,它将实施。

我使用了下面这行if语句…如果选择= = 1、3、10,,选择2==1,3,10 &7选择3==1,3,10),然后执行动作…

if((select == 1 || 3 || 10) &&(choice2== 1 || 3 || 10) &&(choice3== 1 || 3 || 10)) then execute action…

我已经尝试了上面的那些,但是它不会执行下面的语句…但是它会执行上面那个…

#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]   -  Anglen");
        printf("[2]   -  Degreen");
        printf("[3]   -  Radiusn");
        printf("[4]   -  Length of Curven");           
        printf("[5]   -  Tangentn");
        printf("[6]   -  Chordn");
        printf("[7]   -  Midordinaten");
        printf("[8]   -  External Distancen");
        printf("[9]   -  Point of Intersectionn");
        printf("[10]  -  Point of Curven");
        printf("[11]  -  Point of Tangentn");
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 = %lfn",angle);
        printf("Radius = %lfn",radius);
        printf("Point of Intersection (PI) = %lf + %lfn", 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 = %lfn",radius);
        printf("Length of Curve = %lfn",length);
        printf("Tangent = %lfn",tangent);
        printf("Chord = %lfn",chord);
        printf("Mid Ordinate = %lfn",midordinate);
        printf("External Distance = %lfn",external);
        printf("Point of Intersection = %lfn",pintersect);
        printf("Point of Curve = %lfn",pcurve);
        printf("Point of Tangent = %lfn",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 = %lfn",angle);
        printf("Radius = %lfn",radius);
        printf("Point of Curve (PC) = %lf - %lfn", 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 = %lfn",radius);
        printf("Length of Curve = %lfn",length);
        printf("Tangent = %lfn",tangent);
        printf("Chord = %lfn",chord);
        printf("Mid Ordinate = %lfn",midordinate);
        printf("External Distance = %lfn",external);
        printf("Point of Intersection = %lfn",pintersect);
        printf("Point of Curve = %lfn",pcurve);
        printf("Point of Tangent = %lfn",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 = %lfn",angle);
        printf("Radius = %lfn",radius);
        printf("Point of Curve (PC) = %lf + %lfn", 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 = %lfn",radius);
        printf("Length of Curve = %lfn",length);
        printf("Tangent = %lfn",tangent);
        printf("Chord = %lfn",chord);
        printf("Mid Ordinate = %lfn",midordinate);
        printf("External Distance = %lfn",external);
        printf("Point of Intersection = %lfn",pintersect);
        printf("Point of Curve = %lfn",pcurve);
        printf("Point of Tangent = %lfn",ptan);
}


}

getch();
return 0;
}
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))