Thread: The program is skipping if statement

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    2

    The program is skipping if statement

    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;	
    	}


    The program is skipping if statement-untitled-jpg

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,489
    Code:
            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);
    Where your "%c" conversions follow some other scanf, you should include a leading space in the conversion.

    Eg.
    Code:
            scanf(" %c",&M_Choice);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    2
    Quote Originally Posted by Salem View Post
    Code:
            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);
    Where your "%c" conversions follow some other scanf, you should include a leading space in the conversion.

    Eg.
    Code:
            scanf(" %c",&M_Choice);
    Thank you,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My program is skipping my second getchar() input statement.
    By UncleBazerko in forum C Programming
    Replies: 2
    Last Post: 09-20-2018, 11:37 AM
  2. cin statement skipping
    By joe6032 in forum C++ Programming
    Replies: 1
    Last Post: 10-06-2014, 10:35 PM
  3. Program skipping if statement
    By russiancircles in forum C++ Programming
    Replies: 0
    Last Post: 03-16-2014, 05:55 PM
  4. skipping switch statement
    By psppb in forum C Programming
    Replies: 14
    Last Post: 07-25-2012, 05:43 AM
  5. Skipping if statement
    By FallenBlade in forum C Programming
    Replies: 6
    Last Post: 12-13-2009, 03:40 PM

Tags for this Thread