在C中选择三个选项(多选)
Select three choices (multiple choices) in C
嗨,我正在做一个计算器,我可以选择解决什么问题。首先,你会被问到你有多少。对于这段代码,我让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))
相关文章:
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 在 2D 向量中使用第三个 [ ] 有什么意义?
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 如何知道n!是否可以表示为三个连续数字的乘法?
- 我有三个 getline,但是一旦编译,输入就太多了
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 有没有更好的方法对C++中的三个整数进行排序?
- 如何检查第三个 API 是否在 Linux 中为 c/c++ 程序创建了一个新线程?
- 为什么 getch 在按下函数或箭头键时返回三个值?
- 使用三个数字比较器进行排序
- 我想在C++代码中比较这三个术语
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 我该如何编码,使计算机知道两个名称条目和三个名称条目之间的区别
- 为什么我需要三个嵌套的大括号来调用赋值运算符,将const引用到二维数组
- 如何通过通用引用或std::forward将这三个c++模板函数合并为一个
- 首先处理第二个和第三个堆与第一个和第二个堆之间的逻辑差异
- 异常处理:如果用户输入不是三个特定字符之一
- 为什么将三个变量与 == 一起比较会计算为 false?
- if语句在有两个OR选项的第三个条件下不起作用
- 在C中选择三个选项(多选)