• Log in or sign up for an account here: https://www.sythe.org/login

Need help with my code

Status
Not open for further replies.

d great one

Apprentice
Joined
Nov 4, 2007
Sythe Gold
0
Messages
930
#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 ();
}
This is the original thread http://sythe.org/showthread.php?p=3723347#post3723347

That is my latest code.

this is the suppose outcome

Welcome to deal or no deal.
Cases are 1 - 14
Enter case number: 3

Banker's offer is 3000
D = Deal N = No Deal
Deal or no deal? n

The case contains 1000
You win

When I choose D (deal), I get the right response, but when I choose N (no deal) I don't get the right response. I tried to put as well a last else statement

else
{
printf ("Invalid choice");
}

but when I press other number, it won't give me an invalid choice. Please help me fix this.

Thanks.


EDIT: Wrong quotation
 
Status
Not open for further replies.
Runescape Gamblingrunescape gambling
Back
Top