I am trying to ask a user if they would like to try again a new computation, I used old code from another lab I had but can't seem to get it to adjust proper for this new one.
My problem is that when it asks the user it will loop fine when you start with y and then ask you for a new input x:
However, when you enter n it will make you do it twice. And the second time can literally be any number or character. I have been at this all day. I cannot seem to find where I am getting this wrong.
This is a lab for school, so we have not yet moved to using stdin etc.. just the basics.
char usercont() // prompt user to solve another
{
char y_n;
printf("\nWould you like to solve another? Enter 'y' for yes or 'n' for no: ");
while ((y_n = getchar()) == '\n' || y_n == EOF);
return y_n;
}
double eval_poly()
{
while (1)
{
int varx; // set the value of variable x in the equation from above. This x is different from the looping x count
printf("\nInput x:");
scanf("%d", &varx);
double result = 0.0;
for (int i = 0; i < x; i++)
{
result += numbers[i] * pow(varx, i);
}
printf("Evaluated result: %lf\n", result);
int c;
while ((c = getchar()) != '\n' && c != EOF);
if (usercont() =='n') // need to enter twice cant seem to fix
{
break;
}
else
{
continue;
}
}
}
MY issue was in main where I list the usercont to execute after the evalpoly. Alas I thought I had already tried deleting that and it cause a seperate error.
{
getpoly();
eval_poly();
usercont();
system("pause");
return 0;
}```
calling usercont caused the the line to run agaain but when deleted it accepts the first n