Welcome to deal or no deal. Cases are 1 - 14 Enter case number: 1 Banker's offer is 10000 D = Deal N = No Deal Deal or no deal? d The case contains 3000 You win |
#include <stdio.h> #include <iostream> #include <time.h> #include <conio.h> int a,b; main() { short unsigned int num = 0; short unsigned int num2 = 0; char test; srand(time(NULL)); loot: num = 1 + rand() % (14 - 1 + 1); num2 = 1 + rand() % (14 - 1 + 1); 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"); } getch (); } |
[QUOTE] scanf ("%",&test); |
1st Your case-statements do not make sense. You forget the test == 'D' to assign a new value to test. 2md If ('d' || 'D') does not make sense. You need to compare your variable "test" with the letters: --> f (Test =='d') int main |
Can you show me? I tried to put if (test == 'd' || test 'D')" Should be if(test == 'd' || test == 'D') |
|
|
#include <stdio.h> #include <iostream> #include <time.h> #include <conio.h> int a,b; main() { short unsigned int num = 0; short unsigned int num2 = 0; char test; srand(time(NULL)); num = 1 + rand() % (14 - 1 + 1); num2 = 1 + rand() % (14 - 1 + 1); 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 (); } |
fflush(stdin);