My switch statement embedded in my do loop doesn't seem to execute correctly:
Code:
#include <stdio.h>
#include <math.h>
int main()
{
double x, y, y2;
int n_term;
printf("Enter -1<x<1 : ");
scanf("%lf",&x);
y = log (x);
printf("\nTrue value of log(1+x) = %.5f\n\n",y);
do {
printf("Enter an integer 1-4; 0 to Exit\n");
scanf("%d",&n_term);
switch (n_term){
case '1':
printf("\n1 term approximation\n");
y2 = x;
printf("Approximate log(1+x) = %.5f",y2);
break;
case '2':
printf("\n2 term approximation\n");
y2 = x - (pow(x,2)/2);
printf("Approximate log(1+x) = %.5f",y2);
break;
case '3':
printf("\n2 term approximation\n");
y2 = x - (pow(x,2)/2) + (pow(x,3)/3);
break;
printf("Approximate log(1+x) = %.5f",y2);
case '4':
y2 = x - (pow(x,2)/2) + (pow(x,3)/3) - (pow(x,4)/4);
break;
case '0':
break;
default:
printf("unrecognized operator");
break;
}
}
while (n_term != 0);
scanf("%lf",&x);
}
Instead of correctly recognizing the "#" term approximation, it prints a blank line. Anyone have some input?