1. Problem with While loop

This is, what seemed like, a pretty simple homework assignment. I've tested it using all the menu options including an invalid response, and everything works perfectly, but it seems to exit the loop even if I say Y/y at the end one run-through.

Any help would be appreciated.

Code:
```#include <stdio.h>

int get_problem();
void get2_pt(double *x_onep, double *y_onep, double *x_twop, double *y_twop);
void get_pt_slope(double *x_onep, double *y_onep, double *slopep);
void slope_intcpt_from2_pt(double x_one, double y_one, double x_two, double y_two, double *slopep, double *y_intp);
double intcpt_from_pt_slope(double x_one, double y_one, double slope);
void display2_pt(double x_one, double y_one, double x_two, double y_two);
void display_pt_slope(double x_one, double y_one, double slope);
void display_slope_intcpt(double slope, double y_int);

int
main(void)
{
double x_one,
x_two,
y_one,
y_two,
slope,
y_int;
int problem;
char cont;

cont = 'Y';
while (cont == 'Y' || cont == 'y') {
problem = get_problem();
if (problem == 1) {
get2_pt(&x_one, &y_one, &x_two, &y_two);
slope_intcpt_from2_pt(x_one, y_one, x_two, y_two, &slope, &y_int);
display2_pt(x_one, y_one, x_two, y_two);
display_slope_intcpt(slope, y_int);
printf("\n\nDo another conversion? (Y/N): ");
scanf("%c", &cont);
}
else if (problem == 2) {
get_pt_slope(&x_one, &y_one, &slope);
y_int = intcpt_from_pt_slope(x_one, y_one, slope);
display_pt_slope(x_one, y_one, slope);
display_slope_intcpt(slope, y_int);
printf("\n\nDo another conversion? (Y/N): ");
scanf("%c", &cont);
}
else if (problem == 3) {
printf("Exiting Program");
cont = 'N';
}
else {
cont = 'Y';
}
}

return(0);
}

int
get_problem()
{
int problem;

printf("Select the form that you would like to convert to slope intercept form:");
printf("\n1) Two-point form (you know two points on the line)");
printf("\n2) Point-slope form (you know the line's slope and one point)");
printf("\n3) Exit");
printf("\n\n>> ");
scanf("%d", &problem);
return(problem);
}

void
get2_pt(double *x_onep, double *y_onep, double *x_twop, double *y_twop)
{
double one,
two;
printf("\nEnter the coordinates of the first point separated by one space: ");
scanf("%lf %lf", &one, &two);
*x_onep = one;
*y_onep = two;
printf("Enter the coordinates of the second point: ");
scanf("%lf %lf", &one, &two);
*x_twop = one;
*y_twop = two;
}

void
get_pt_slope(double *x_onep, double *y_onep, double *slopep)
{
double x,
y,
slope;
printf("\nEnter the coordinates of the known point separated by one space: ");
scanf("%lf %lf", &x, &y);
printf("Enter the slope of the line: ");
scanf("%lf", &slope);
*x_onep = x;
*y_onep = y;
*slopep = slope;
}

void
slope_intcpt_from2_pt(double x_one, double y_one, double x_two, double y_two, double *slopep, double *y_intp)
{
*slopep = ((y_two - y_one) / (x_two - x_one));
*y_intp = (y_one - (*slopep * x_one));
}

double
intcpt_from_pt_slope(double x_one, double y_one, double slope)
{
double y_int;

y_int = y_one - (slope * x_one);
return(y_int);
}

void
display2_pt(double x_one, double y_one, double x_two, double y_two)
{
printf("\nTwo-point form");
printf("\n   (%.2f - %.2f)", y_two, y_one);
printf("\nm = -----------");
printf("\n   (%.2f - %.2f)", x_two, x_one);
}

void
display_pt_slope(double x_one, double y_one, double slope)
{
printf("\nPoint-slope form");
printf("\n  y - %.2f = %.2f(x - %.2f)", y_one, slope, x_one);
}

void
display_slope_intcpt(double slope, double y_int)
{
printf("\n\nSlope-intercept form");
printf("\n  y = %.2fx - %.2f", slope, y_int);
}```

2. Try replacing this

Code:
`scanf("%c", &cont);`
with this

Code:
`scanf(" %c", &cont);`
I know it seems stupid, but it does make a difference. White space isn't ignored by %c, unlike the rest of the options so it's very possible cont equals something other than the 'y'/'Y' you think it is by mistake.

3. That fixed it, thanks!

4. You're welcome

5. Originally Posted by whiteflags
White space isn't ignored by %c, unlike the rest of the options so it's very possible cont equals something other than the 'y'/'Y' you think it is by mistake.
None of the options ignore whitespace. The f in the scanf and printf functions mean "formatted". It reads (or writes) exactly what you tell it to expect.

Quzah.

6. None of the options ignore whitespace.
I'll correct myself in this manner.

Input white-space characters (as specified by isspace()) shall be skipped, unless the conversion specification includes a [, c, C, or n conversion specifier.
fscanf