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

I need help with the program I'm making

Status
Not open for further replies.

d great one

Apprentice
Joined
Nov 4, 2007
Sythe Gold
0
Messages
930
I need help with the program I'm making
Basically the output would be

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

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

The case contains 2000
You win
Press any key to continue . . .


The program is

#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 letter;
loop:

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 ("%",&letter);
b=num2*1000;
printf ("\nThe case contains %d",b);
switch (letter)

if (letter == 'n' || letter == 'N')
{
if (a < b) goto win;
else if (a > b) goto lose;
else if (a == b) goto same;
}
else if (letter == 'd' || letter == 'D')
{
if (a > b) goto win;
else if (a < b) goto lose;
else if (a == b) goto same;
}
win:
{
printf ("\nYou win\n");
system ("pause");
return 0;
}
lose:
{
printf ("\nYou lost\n");
system ("pause");
return 0;
}
same:
{
printf ("\nBanker's offer and case is just the same\n");
system ("pause");
return 0;
}
getch();
}


I need help, because sometimes when the case has higher value than the banker's offer and I pick 'D' (no deal) I still get to win.

The main problem is I don't get the right result in winning or losing.

Please help me.

If the section forum is wrong, please move and notify me. Thanks.
 
I need help with the program I'm making
I'm not going to fix it for you. I'm going to tell you how to fix it.

But first of all, don't use the goto statement. If you do, you're practically asking for terrible code.

http://www.kevinboone.com/ctut_switch.html

Read up.
 
I need help with the program I'm making
I'm not going to fix it for you. I'm going to tell you how to fix it.

But first of all, don't use the goto statement. If you do, you're practically asking for terrible code.

http://www.kevinboone.com/ctut_switch.html

Read up.

Ok, so just give me a hint on how to put the win lost same in the switch/case syntax. Or is it possible to combine switch/case with if else?
 
I need help with the program I'm making
I still get a funny random result

#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': printf ("\nDeal"); break;
case 'n': case 'N': printf ("\nNo deal"); 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 ("Banker'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 ("Banker's offer and case is just the same");
}
}
}
getch ();
}
 
I need help with the program I'm making
You want to use a switch statement where all of those hideous if/else/if blocks are.
 
I need help with the program I'm making
#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 ();
}


Now I get the right response when I press D, but when I press N, not right response.
 
I need help with the program I'm making
This is my latest code. Only made worse. Someone please please please help me out.

#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 ();
}


Would be better if you test run it. Would help to figure what went wrong (which I can't really figure). Please someone save me!
 
I need help with the program I'm making
YES! I got here before anyone else posted a final response!

Ok, d great one, go to http://bloodshed.net and download the latest version of their C++ Compiler Package. Then, after you unzip and install it, there should be an 'Examples' folder with another folder named 'Jackpot'. Open that up and edit it, it's the closest thing to deal or no deal that i have used.....=)
 
I need help with the program I'm making
first off why do you have (14-1+1)?...isn't that the same as (14+0) or just 14....anyway...

your not using the switch right...and you should use variables that better explain instead of arbitrary letters...
 
I need help with the program I'm making
I already solved his problem via PM.

Useless thread is useless.
 
Status
Not open for further replies.
Runescape Gamblingrunescape gambling
Back
Top