printf ("Welcome to deal or no deal.\nCases are 1 - 14");
printf ("\nEnter case number: ");
scanf ("%d", &a);
a=num*1000;
printf ("\nBanker's offer is %d", a);
printf ("\nD = Deal N = No Deal\nDeal or no deal? ");
scanf ("%",&test);
b=num2*1000;
printf ("\nThe case contains %d",b);
switch (test)
{
case 'd': case 'D': break;
case 'n': case 'N': break;
case 'c': case 'C': return (0); break;
}
if ('d' || 'D')
if (a > b)
{
printf ("\nYou win");
}
else if (a < b)
{
printf ("\nYou lost");
}
else
{
printf ("\nBanker's offer and case is just the same");
}
else if ('n' || 'N')
if (a < b)
{
printf ("\nYou win");
}
else if (a > b)
{
printf ("\nYou lost");
}
else
{
printf ("\nBanker's offer and case is just the same");
}
Also, you could replace your line with scanf() with:
1 2
test = (char) fgetc(stdin);
fflush(stdin);
Also remember this is a forum, not quite an active conversation, and your peers are volunteering information. Have patience, or eventually nobody will want to respond.
printf ("Welcome to deal or no deal.\nCases are 1 - 14");
printf ("\nEnter case number: ");
scanf ("%d", &a);
a=num*1000;
printf ("\nBanker's offer is %d", a);
printf ("\nD = Deal N = No Deal\nDeal or no deal? ");
scanf ("%c",&test);
b=num2*1000;
printf ("\nThe case contains %d",b);
switch (test)
{
case 'd': case 'D': break;
case 'n': case 'N': break;
case 'c': case 'C': return (0); break;
}
if (test == 'd' || test == 'D')
{
if (a > b)
{
printf ("\nYou win");
}
else if (a < b)
{
printf ("\nYou lost");
}
else
{
printf ("\nBanker's offer and case is just the same");
}
}
else if (test == 'n' || test == 'N')
{
if (a < b)
{
printf ("\nYou win");
}
else if (a > b)
{
printf ("\nYou lost");
}
else
{
printf ("\nBanker's offer and case is just the same");
}
}
getch ();
}
That is my latest code. See how it works for yourself. Well, at least try it before you tell me what is wrong.
And I can't use other code aside from scanf printf switch case and if else. That is what my professor said. And now I can't even pull it off.
Please try it before you tell me what is wrong. Thanks.
because the user enters a newline (hits enter) just before your scanf goes off, the scanf is picking up the newline character rather than the character you type in. Add a second character to the scanf, pull in the first one as trash, and then pull in the second one as test, it should work after that.