I wrote this really simple code to find resistor values. the code will compile and asks the initial question but when an input of P or S is inputted the code crashes and exits. Any help would be great, I know it will be something really simple I'm missing out...
#include <stdio.h>
void main ()
{
float res1;
float res2;
float res3;
float answer;
char calctype;
printf("Please enter 1st resistor value:");
scanf("%f", &res1);
printf("Enter 2nd resistor value:");
scanf("%f", &res2);
printf("Enter 3rd resistor value:");
scanf("%f", &res3);
puts("type P for Parallel calculation or S for Series calculation:\n");
scanf("%c", calctype);
if (calctype == 'S') {
answer = res1 + res2 + res3;
printf("The Series value is:%f \n", answer);
}
else if (calctype == 'P') {
answer = 1/(1/res1 + 1/res2 + 1/res3);
printf("The Parallel Value is:%f \n", answer);
}
}
Thank you!