pls fix my deal or no deal program

This is a discussion on pls fix my deal or no deal program within the C Programming forums, part of the General Programming Boards category; i want that if in case the player input again a repeated briefcases it will go back again Code: #include ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    19

    pls fix my deal or no deal program

    i want that if in case the player input again a repeated briefcases it will go back again

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    int y_brief;
    int o_brief[25];
    int n=0,m=0;
    int rnd;
    int g,h,i;
    
    int x1[26]={27,32,37,42,47,52,25,30,35,40,45,50,55,25,30,35,40,45,50,55,27,32
    ,37,42,47,52};
    int y1[26]={16,16,16,16,16,16,13,13,13,13,13,13,13,10,10,10,10,10,10,10,7,7,7
    ,7,7,7};
    int x2[26]={4,4,4,4,4,4,4,4,4,4,4,4,4,64,64,64,64,64,64,64,64,64,64,64,64,64};
    int y2[26]={7,8,9,10,11,12,13,14,15,16,17,18,19,7,8,9,10,11,12,13,14,15,16,17
    ,18,19};
    
    long int c_brief[26]={1,5,10,25,50,75,100,150,200,250,300,400,500,1000,2500,
    5000,10000,25000,50000,75000,100000,250000,500000,1000000,2000000,3000000};
    long int a_brief[26]={1,5,10,25,50,75,100,150,200,250,300,400,500,1000,2500,
    5000,10000,25000,50000,75000,100000,250000,500000,1000000,2000000,3000000};
    
    long int sum[9];
    long int temp;
    
    double b_offer[9];
    double percentage[9];
    
    char Resp=0;
    
    
    marking(){
    	for(i = 0;i < 26; i++){
    		if (o_brief[n] == (i+1)){
    			gotoxy(x1[i], y1[i]);
    			printf("  ");}
    	}
    	for(i = 0;i < 26; i++){
    		if(c_brief[o_brief[n]-1]==a_brief[i]){
    			gotoxy(68,23);
    			printf("%7ld",a_brief[i]);
    			sleep(2);
    			gotoxy(67,23);
    			printf("         ");
    			gotoxy(x2[i], y2[i]);
    			printf("*");}
    	}
    	return;
    }
    
    banker_offer(){
    	gotoxy(29,19);
    	printf("      Calculating..           ");
            gotoxy(29,20);
    	printf("     旼컴컴컴컴컴컴          ");
            gotoxy(29,21);
    	printf("                            ");
    	gotoxy(29,22);
    	printf("     읕컴컴컴컴컴컴          ");
    	sleep(5);
    	gotoxy(29,19);
    	printf("    banker offers you         ");
    	gotoxy(37,21);
    	printf("%7.0lf",b_offer[h]);
    	gotoxy(29,23);
    	printf("   [D]eal or [N]o Deal        ");
    	return;
    }
    
    deal(int *y_brief){
    	gotoxy(29,19);
    	printf("     Congratulations          ");
    	gotoxy(29,20);
    	printf("  You closed a deal for       ");
    	gotoxy(29,21);
    	printf("     旼컴컴컴컴컴컴          ");
    	gotoxy(29,22);
    	printf("                            ");
    	gotoxy(29,23);
    	printf("     읕컴컴컴컴컴컴          ");
    	gotoxy(37,22);
    	printf("%7.0lf",b_offer[g]);
    	gotoxy(67,23);
    	printf("%7ld",c_brief[*y_brief]);
    	gotoxy(4,21);
    	printf("              ");
    	gotoxy(64,21);
    	printf("your briefcase");
    	getch();
    }
    
    round_9(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 9        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 1 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[8]=sum[8]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<23);
    
    	percentage[8]=rand() % ((85 - 70) + 1) + 70;
    	b_offer[8]=((7020566-sum[0]-sum[1]-sum[2]-sum[3]-sum[4]-sum[5]-sum[6]
    	-sum[7]-sum[8]) / 2) * (percentage[8] / 100);
    
    	banker_offer(h=8);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=8);
    	if(Resp==110)
    	gotoxy(29,19);
    	printf("       Game is over           ");
    	gotoxy(29,20);
    	printf(" Your briefcase contained     ");
    	gotoxy(29,21);
    	printf("     旼컴컴컴컴컴컴          ");
    	gotoxy(29,22);
    	printf("                            ");
    	gotoxy(29,23);
    	printf("     읕컴컴컴컴컴컴          ");
    	gotoxy(37,22);
    	printf("%7ld",c_brief[y_brief-1]);
    	getch();
    }
    
    round_8(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 8        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 1 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[7]=sum[7]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<23);
    
    	percentage[7]=rand() % ((75 - 60) + 1) + 60;
    	b_offer[7]=((7020566-sum[0]-sum[1]-sum[2]-sum[3]-sum[4]-sum[5]-sum[6]
    	-sum[7]) / 3) * (percentage[7] / 100);
    
    	banker_offer(h=7);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=7);
    	if(Resp==110);
    	round_9();
    }
    
    round_7(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 7        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 1 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[6]=sum[6]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<22);
    
    	percentage[6]=rand() % ((65 - 50) + 1) + 50;
    	b_offer[6]=((7020566-sum[0]-sum[1]-sum[2]-sum[3]-sum[4]-sum[5]-sum[6]
    	) / 4) * (percentage[6] / 100);
    
    	banker_offer(h=6);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=6);
    	if(Resp==110)
    	round_8();
    }
    
    round_6(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 6        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 1 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[5]=sum[5]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<21);
    
    	percentage[5]=rand() % ((55 - 40) + 1) + 40;
    	b_offer[5]=((7020566-sum[0]-sum[1]-sum[2]-sum[3]-sum[4]-sum[5]) / 5)
    	 * (percentage[5] / 100);
    
    	banker_offer(h=5);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=5);
    	if(Resp==110)
    	round_7();
    }
    
    round_5(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 5        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 2 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[4]=sum[4]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<20);
    
    	percentage[4]=rand() % ((45 - 30) + 1) + 30;
    	b_offer[4]=((7020566-sum[0]-sum[1]-sum[2]-sum[3]-sum[4]) / 6) *
    	(percentage[4] / 100);
    
    	banker_offer(h=4);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=4);
    	if(Resp==110)
    	round_6();
    }
    
    round_4(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 4        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 3 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[3]=sum[3]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<18);
    
    	percentage[3]=rand() % ((35 - 20) + 1) + 20;
    	b_offer[3]=((7020566-sum[0]-sum[1]-sum[2]-sum[3]) / 8)
    	 * (percentage[3] / 100);
    
    	banker_offer(h=3);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=3);
    	if(Resp==110)
    	round_5();
    }
    
    round_3(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 3        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 4 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[2]=sum[2]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<15);
    
    	percentage[2]=rand() % ((30 - 15) + 1) + 15;
    	b_offer[2]=((7020566-sum[0]-sum[1]-sum[2]) / 11)
    	 * (percentage[2] / 100);
    
    	banker_offer(h=2);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=2);
    	if(Resp==110)
    	round_4();
    }
    
    round_2(){
    	gotoxy(29,19);
    	printf("                             ");
            gotoxy(29,20);
    	printf("      Round 2        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 5 briefcases!   읕켸    ");
    	gotoxy(29,23);
    	printf("                             ");
    
            do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[1]=sum[1]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<11);
    
    	percentage[1]=rand() % ((25 - 10) + 1) + 10;
    	b_offer[1]=((7020566-sum[0]-sum[1]) / 15) * (percentage[1] / 100);
    
    	banker_offer(h=1);
    
            Resp=getch();
    	if(Resp==100)
    	deal(g=1);
    	if(Resp==110)
    	round_3();
    }
    
    round_1(){
    	gotoxy(30,20);
    	printf("Choose your briefcase!");
    	gotoxy(10,23);
    	scanf("%d",&y_brief);
    
    	for(i = 0;i < 26; i++){
    		if(y_brief==1+i)
    		{
    			gotoxy(x1[i], y1[i]);
    			printf("  ");
    		}
    	}
    
    	gotoxy(29,20);
    	printf("      Round 1        旼커    ");
    	gotoxy(29,21);
    	printf("                           ");
    	gotoxy(29,22);
    	printf("Open 6 briefcases!   읕켸    ");
    
    	do{
    	gotoxy(51,21);
    	scanf("%d",&o_brief[n]);
    	gotoxy(51,21);
    	printf("  ");
    
    	marking();
    
    	sum[0]=sum[0]+c_brief[o_brief[n]-1];
    	n++;
    	}while(n<6);
    	percentage[0]=rand() % ((20 - 5) + 1) + 5;
    	b_offer[0]=((7020566 - sum[0]) / 20) * (percentage[0] / 100);
    
    	banker_offer(h=0);
    
    	Resp=getch();
    	if(Resp==100)
    	deal(g=0);
    	if(Resp==110)
    	round_2();
    }
    
    void main(){
    	srand(time(NULL));
    	textbackground(15);
    	textcolor(0);
    	clrscr();
    	while(m<26){
    		rnd=rand()%26;
    		temp=c_brief[m];
    		c_brief[m]=c_brief[rnd];
    		c_brief[rnd]=temp;
    		m++;
    	}
    	gotoxy(2,1);
    	printf("袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴");
    	gotoxy(2,2);
    	printf("                                                                            ");
    	gotoxy(2,3);
    	printf("                                                                            ");
    	gotoxy(2,4);
    	printf("勁袴袴袴袴袴袴袴藁袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴箇袴袴袴袴袴袴袴攷");
    	gotoxy(2,5);
    	printf("                                                                          ");
    	gotoxy(2,6);
    	printf("                      旼커 旼커 旼커 旼커 旼커 旼커                       ");
    	gotoxy(2,7);
    	printf("             1        21 22 23 24 25 26                1,000  ");
    	gotoxy(2,8);
    	printf("             5        읕켸 읕켸 읕켸 읕켸 읕켸 읕켸                2,500  ");
    	gotoxy(2,9);
    	printf("            10      旼커 旼커 旼커 旼커 旼커 旼커 旼커             5,000  ");
    	gotoxy(2,10);
    	printf("            25      14 15 16 17 18 19 20            10,000  ");
    	gotoxy(2,11);
    	printf("            50      읕켸 읕켸 읕켸 읕켸 읕켸 읕켸 읕켸            25,000  ");
    	gotoxy(2,12);
    	printf("            75      旼커 旼커 旼커 旼커 旼커 旼커 旼커            50,000  ");
    	gotoxy(2,13);
    	printf("           100      7  8  9  10 11 12 13            75,000  ");
    	gotoxy(2,14);
    	printf("           150      읕켸 읕켸 읕켸 읕켸 읕켸 읕켸 읕켸           100,000  ");
    	gotoxy(2,15);
    	printf("           200        旼커 旼커 旼커 旼커 旼커 旼커              250,000  ");
    	gotoxy(2,16);
    	printf("           250        1  2  3  4  5  6               500,000  ");
    	gotoxy(2,17);
    	printf("           300        읕켸 읕켸 읕켸 읕켸 읕켸 읕켸            1,000,000  ");
    	gotoxy(2,18);
    	printf("           400                                                 2,000,000  ");
    	gotoxy(2,19);
    	printf("           500                                                 3,000,000  ");
    	gotoxy(2,20);
    	printf("                                                                          ");
    	gotoxy(2,21);
    	printf(" your briefcase                                                           ");
    	gotoxy(2,22);
    	printf("      旼커                                                  旼컴컴컴컴커  ");
    	gotoxy(2,23);
    	printf("                                                                      ");
    	gotoxy(2,24);
    	printf("      읕켸                                                  읕컴컴컴컴켸  ");
    	gotoxy(2,25);
    	printf("훤袴袴袴袴袴袴袴菰袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴袴姦袴袴袴袴袴袴袴暠");
    	round_1();
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by llinocoe View Post
    i want that if in case the player input again a repeated briefcases it will go back again
    uhm.. what? sorry i cant make any sense of that. your the only one that knows your program inside and out (supposedly), so explain more what 'in case player input again' and 'it will go back again' mean.

    i think you made a thread about putting similar code into functions to reduce the size, but there is still a lot of repeated code.

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Sweet mother of god - it's the code from hell!
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by IceDane View Post
    Sweet mother of god - it's the code from hell!
    ROFL! ROFL! ROFL!

    EDIT: Seriously you made me laugh. And I don't laugh easily

    EDIT2: But even more seriously. llinocoe fix your code. Make it readable. The whole idea of round_X functions doesn't help, it should be one function somehow. In any case you MUST do one of the following:
    1) Make it more readable
    2) Highlight the part of the codes that don't deal with printing, so we can easily read the rest that causes the problem. The code that has to do with printing includes the gotoxy before printing and any if () printf;
    3) Well, you know. Explain what the problem better
    Last edited by C_ntua; 09-23-2008 at 01:45 AM.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    1. remove all the gotoxy() calls. They add NOTHING in terms of the functionality of the program, and they just create clutter. When (and I stress WHEN) the code is working as you want, then you can go round tarting up the display by putting gotoxy() calls all over the place.

    2. Have you looked at all your round_x functions?
    Seriously, you should have been thinking "what are the parameters" while you were busy copy/pasting the same thing over and over.

    3. deal(int *y_brief)
    Mmm, ok, but then what does this mean?
    deal(g=0);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I don't believe you need to have so many functions. There is no need to even use a pointer for the deal() function at all. Actually, your algorithm for determining the banker's offer seems a little suspicious too. I do not watch the show enough to know their exact algorithm, but how they determine the offer has been discussed on many other threads.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pls debug my scroll program
    By Raison in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2004, 07:30 PM
  2. Help writing calculator program (newbie)
    By Danny 2 in forum C Programming
    Replies: 3
    Last Post: 07-25-2002, 06:44 AM
  3. Replies: 7
    Last Post: 07-19-2002, 04:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21