Hello,
i have a problem with my code which is skipping the if statement (M_choice)
Code:
#include <stdio.h>#include <math.h>
#define PI 3.14159
#define E0 8.85E-12 // This Value is the permittivity of free space
int main(void){
double Er_Air=1.000594, Er_Teflon=2.1, Er_Ceramic=5.6, Er_Glass=7.5, Er_Silicon=11.68;
// Those values representing the relative permittivity of common dielectrics
double Pplates, PlateArea, Distance, Spherical, InnerR, OuterR, Cylindrical, Lingth;
char C_Choice, M_Choice;
printf(" ------ Capacitance Calculator ------ \n");
printf("[P/p]\tParallel Plates\n[C/c]\tCylindrical\n[S/s]\tSpherical");
printf("\n\tPlease Enter Your Choice : ");
scanf("%c",&C_Choice);
if(C_Choice=='P'||C_Choice=='p'||C_Choice=='S'||C_Choice=='s'||C_Choice=='c'||C_Choice=='C'){
if(C_Choice=='P'||C_Choice=='p'){
printf(" ------------------------------------ \n");
printf("Parallel_Plates capacitor:\n");
printf("Enter The Area\t\t\t:");
scanf("%lf",&PlateArea);
printf("Enter The Distance Between plates\t:");
scanf("%lf",&Distance);
printf("\n\nDielectrics:");
printf("\n\tAir\t\tTeflon\t\tCeramic\t\tPaper\t\tGlass\t\tSilicon");
printf("\nEnter The First Litter Of Dielectric Type:");
scanf("%c",&M_Choice);
if(M_Choice=='A'||M_Choice=='a'){
double E;
E=E0*Er_Air;
Pplates=E*(PlateArea/Distance);
printf("\nCapacitance = %f micro Farad",Pplates);
}
else if(M_Choice=='T'||M_Choice=='t'){
double E;
E=E0*Er_Teflon;
Pplates=E*(PlateArea/Distance);
printf("\nCapacitance = %f micro Farad",Pplates);
}
else if(M_Choice=='C'||M_Choice=='c'){
double E;
E=E0*Er_Ceramic;
Pplates=E*(PlateArea/Distance);
printf("\nCapacitance = %f micro Farad",Pplates);
}
else if(M_Choice=='G'||M_Choice=='g'){
double E;
E=E0*Er_Glass;
Pplates=E*(PlateArea/Distance);
printf("\nCapacitance = %f micro Farad",Pplates);
}
else if(M_Choice=='S'||M_Choice=='s'){
double E;
E=E0*Er_Silicon;
Pplates=E*(PlateArea/Distance);
printf("\nCapacitance = %f micro Farad",Pplates);
}
else
printf("Your choise is wrong");
}
else if(C_Choice=='S'||C_Choice=='s'){
printf(" ------------------------------------ \n");
printf("Parallel_Plates capacitor:\n");
printf("Enter The Inner Radius\t:");
scanf("%lf",&InnerR);
printf("Enter The Outer Radius\t:");
scanf("%lf",&OuterR);
printf("\n\nDielectrics:");
printf("\n\tAir\t\tTeflon\t\tCeramic\t\tPaper\t\tGlass\t\tSilicon");
printf("\nEnter The First Litter Of Dielectric Type:");
scanf("%c",&M_Choice);
if(M_Choice=='A'||M_Choice=='a'){
double E;
E=E0*Er_Air;
Spherical=4*PI*E*(InnerR*OuterR/(OuterR-InnerR));
printf("\nCapacitance = %f micro Farad",Spherical);
}
else if(M_Choice=='T'||M_Choice=='t'){
double E;
E=E0*Er_Teflon;
Spherical=4*PI*E*(InnerR*OuterR/(OuterR-InnerR));
printf("\nCapacitance = %f micro Farad",Spherical);
}
else if(M_Choice=='C'||M_Choice=='c'){
double E;
E=E0*Er_Ceramic;
Spherical=4*PI*E*(InnerR*OuterR/(OuterR-InnerR));
printf("\nCapacitance = %f micro Farad",Spherical);
}
else if(M_Choice=='G'||M_Choice=='g'){
double E;
E=E0*Er_Glass;
Spherical=4*PI*E*(InnerR*OuterR/(OuterR-InnerR));
printf("\nCapacitance = %f micro Farad",Spherical);
}
else if(M_Choice=='S'||M_Choice=='s'){
double E;
E=E0*Er_Silicon;
Spherical=4*PI*E*(InnerR*OuterR/(OuterR-InnerR));
printf("\nCapacitance = %f micro Farad",Spherical);
}
else
printf("Your choise is wrong");
}
else if(C_Choice=='c'||C_Choice=='C'){
printf(" ------------------------------------ \n");
printf("Cylindrical capacitor:\n");
printf("Enter The length\t\t\t:");
scanf("%lf",&Lingth);
printf("Enter The radius a (The Inner Radius)\t:");
scanf("%lf",&InnerR);
printf("Enter The radius b (The Outer Radius)\t:");
scanf("%lf",&OuterR);
printf("\n\nDielectrics:");
printf("\n\tAir\t\tTeflon\t\tCeramic\t\tPaper\t\tGlass\t\tSilicon");
printf("\nEnter The First Litter Of Dielectric Type:");
scanf("%c",&M_Choice);
if(M_Choice=='A'||M_Choice=='a'){
double E;
E=E0*Er_Air;
Cylindrical=2*PI*E*(Lingth/log(OuterR/InnerR));
printf("\nCapacitance = %f micro Farad",Cylindrical);
}
else if(M_Choice=='T'||M_Choice=='t'){
double E;
E=E0*Er_Teflon;
Cylindrical=2*PI*E*(Lingth/log(OuterR/InnerR));
printf("\nCapacitance = %f micro Farad",Cylindrical);
}
else if(M_Choice=='C'||M_Choice=='c'){
double E;
E=E0*Er_Ceramic;
Cylindrical=2*PI*E*(Lingth/log(OuterR/InnerR));
printf("\nCapacitance = %f micro Farad",Cylindrical);
}
else if(M_Choice=='G'||M_Choice=='g'){
double E;
E=E0*Er_Glass;
Cylindrical=2*PI*E*(Lingth/log(OuterR/InnerR));
printf("\nCapacitance = %f micro Farad",Cylindrical);
}
else if(M_Choice=='S'||M_Choice=='s'){
double E;
E=E0*Er_Silicon;
Cylindrical=2*PI*E*(Lingth/log(OuterR/InnerR));
printf("\nCapacitance = %f micro Farad",Cylindrical);
}
else
printf("Your choise is wrong");
}
}
else
printf("Error: Your choice is wrong");
return 0;
}