Greeting all,
I have this slippery problem with an if else statement. In my if statement the code originally worked fine until I added the logical 'Or' , and now whether I enter 'y' or 'n' the code executes as if I enter a 'yes' response. All help appreciated, thanks!
Code:
#include <stdio.h>
#include <stdlib.h>
FILE *fptr;
int main()
{
char ansr;
float amnt = 0;
fptr = fopen("MOREDATA.TXT","r+"); /* Opens for output */
if (fptr == 0)
{printf("There was an error opening file");}
else
{printf("Would you like to enter a beginning balance?\n");
printf("Enter 'Y' for yes or 'N' for no\n");
scanf(" %c", &ansr);}
if (ansr == 'Y' || 'y')
{ printf("Enter amount - ");
scanf(" %f",&amnt);
printf("Your beginning balance is %.2f\n", amnt);
fprintf(fptr,"%.2f",amnt);/* Save the amount to the disk file */
}
else
/* if (ansr == 'N' || 'n') */
{ fprintf(fptr,"1000000");
}
fclose(fptr); /* Always close your files */
return 0;
}
Still "eating the elephant one byte at a time" - author not known