AoN
Internet Programmer
- Aug 1, 2012
- 114
This is actually just me messing around out of bordom in class, and this is the third time I've rewritten this thing in the last two hours, but still can't get it to work right. The issue first is seen when entering "n" or "N" for the answer to the first question. It'll display the next question like it's supposed to, but it also displays the first WHILE loop, which shouldn't have been called yet.
When I comment out the second scanf() it skips to the next level, defaulting with question one's answer (expected), but there is displays its WHILE loop which shouldn't have been called yet.
Even tried returning the yn variable to NULL before prompting, no change. Each version I've written has gotten dumber and dumber in the method of coding I've used and I'm starting to run out of ideas on how to dumb it down (almost to single-selection statements).
When I comment out the second scanf() it skips to the next level, defaulting with question one's answer (expected), but there is displays its WHILE loop which shouldn't have been called yet.
Even tried returning the yn variable to NULL before prompting, no change. Each version I've written has gotten dumber and dumber in the method of coding I've used and I'm starting to run out of ideas on how to dumb it down (almost to single-selection statements).
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char yn;
int loop;
printf("Does the damn thing work? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'n' || yn == 'Y' || yn == 'N')
{
if(yn == 'y' || yn == 'Y')
{
printf("Don't screw with it!\n");
}
else
{
printf("Did you screw with it? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'n' || yn == 'Y' || yn == 'N')
{
if(yn == 'y' || yn == 'Y')
{
printf("You dumb ****!\n");
printf("Does anyone know? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'n' || yn == 'Y' || yn == 'N')
{
if(yn == 'y' || yn == 'Y')
{
loop = 1;
while(loop == 1)
{
printf("You poor *******...\n");
printf("Can you blame someone else? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'Y')
{
loop == 0;
}
}
}
else
{
printf("HIDE IT!\n");
}
}
else
{
while(yn != 'y' || yn != 'n' || yn != 'Y' || yn != 'N')
{
printf("You did not enter in Y or N!\n");
printf("Does anyone know? (Y/N) ");
scanf("%c", &yn);
}
}
}
else
{
printf("Will you catch hell? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'n' || yn == 'Y' || yn == 'N')
{
if(yn == 'y' || yn == 'Y')
{
loop = 1;
while(loop == 1)
{
printf("You poor *******...\n");
printf("Can you blame someone else? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'Y')
{
loop == 0;
}
}
}
else
{
printf("****-can it!\n");
}
}
else
{
while(yn != 'y' || yn != 'n' || yn != 'Y' || yn != 'N')
{
printf("You did not enter in Y or N!\n");
printf("Will you catch hell? (Y/N) ");
scanf("%c", &yn);
}
}
}
}
else
{
while(yn != 'y' || yn != 'n' || yn != 'Y' || yn != 'N')
{
printf("You did not enter in Y or N!\n");
printf("Did you screw with it? (Y/N) ");
scanf("%c", &yn);
}
}
}
}
else
{
loop = 1;
while(loop == 1)
{
printf("You did not enter in Y or N!\n");
printf("Does the damn thing work? (Y/N) ");
scanf("%c", &yn);
if(yn == 'y' || yn == 'n' || yn == 'Y' || yn == 'N')
{
loop = 0;
}
}
}
printf("NO PROBLEM!\n\n");
system("pause");
return 0;
}