c++ - Select three choices (multiple choices) in C -
hi working on calculator , have choices on solve. first, asked how many given have. code, made 3 given. default, input 3. next, have list of 11 given in order solve equations. user chose 3 numbers 1-11... have started case using number 1,3,9 , 1,3,10, , 1,3,11. problem when choose 1,3,10 randomly, example change order in input in choice,choice2,choice 3 choosing 3,10,1 instead of 1,3,10...
so let's choose 1,3,10 inputted in order... 10,3,1.. still must go action implement.
i used following line if statement... if(choice==1,3,10 && choice2==1,3,10 &7 choice3==1,3,10) execute action...
and
if( (choice== 1 || 3 || 10) && (choice2== 1 || 3 || 10) && (choice3== 1 || 3 || 10)) execute action...
i've tried above won't execute statements below it... execute 1 above...
#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; }
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){
do consider these conditions valid syntax behave needs ?
correct
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))
Comments
Post a Comment