Thread: [HELP] Deal Or No Deal game.

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    8

    [HELP] Deal Or No Deal game.

    I've been having a problem on how to get started in programming this game, and the deadline is tonight after 8hours.

    Im making a deal or no deal game .




    heres my source code at the moment.

    http://www.mediafire.com/?duzhv655vhmskcv

    I have these problems.

    1.- I need to choose 4 briefcas
    2 - If I press DEAL , the only thing that would output is "You've won : 0 "
    3. If I press No Deal til the end I only get "You've won : 10"

    and im using Bloodshed Dev C - compiler
    Last edited by dnates2012; 09-14-2012 at 01:15 AM.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    Ok, but can you tell me the functions I need atleast?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    You need scanf to read the input, and printf to write the output. I don't think you need any other function.

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    I have my source code , but there are quite alot of problems.


    1.- I need to choose 4 briefcases ; but it opens 5 ,.
    2 - If I press DEAL , the only thing that would output is "You've won : 0 "
    3. If I press No Deal til the end I only get "You've won : 10"

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You should be calling a function and using loops with NO DAMN GOTO'S, in your program. Also, it's VERY hard for people who are used to studying indented (formatted) source code, to figure out unindented code's logic. You're a beginner, so I won't complain about the lack of using decent logic, but it is a witch to go through all those lines of code.

    Have you been taught about (OK to use), functions?

    Playing the game, the banker offers me a HUGE amount of money, on the first Deal or No Deal decision I make. Why is this a random amount, and why so large? When I accept, I'm told instead of the huge amount of money, I will be given winnings of either nothing or almost nothing?? But we had a deal!

    It's VERY late, (almost 3:00 am here), so there's no way to fix this before I go back to bed. IMO, it would need to be re-done - which would be faster to code up than trying to correct your current code.

    That doesn't help you with your deadline for this program, but that's the facts. Stick around, and learn some good C.

  7. #7
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    Ok, sir thank you though - T_T i'll fail ; but the defense will still be on tuesday we still have time to correct .. T_T
    damn so you mean I have to redo all these? T_T

  8. #8
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Indentation is very helpful when reviewing your code. It makes it a lot easier on the eyes, and a lot easier to divide it into meaningful chunks. Kind of like paragraphs in writing.

    I'm only just learning C myself, but I've been told that goto's are extremely bad practice, so you might want to avoid using them.

    Wish you luck, though it seems you missed your deadline.
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by dnates2012 View Post
    Ok, sir thank you though - T_T i'll fail ; but the defense will still be on tuesday we still have time to correct .. T_T
    damn so you mean I have to redo all these? T_T
    I don't know what T_T means.

    What I mean is, it's easier to re-do the program (using some bits of your code from this version), than it is to try and make this program, right.

    I have only a vague idea of how the Deal or No Deal game was played. Can you lay out the way your assignment wants it to be played?

    Specifically, money amounts, and how they change with the number of briefcases opened, etc.

    Can you also write up two sample games, and how they should be played, by the program?

    You have to have some data where the responses are known to be right, so the game program can be quickly tested to see if it's accurate. Without it, you just wander in your coding.

    You do that, and I'll take your program and re-structure it a little, to get it into a form that can be worked on, in a timely manner.

    Not to be too blunt, but I won't help much on anything to do with the program, if your code doesn't have decent indentation on it. Around here, unindented code threads are pretty well ignored entirely.

    Every line of code which is dependent on another line of code before it, must be indented 2 to 5 char's. (I use 3 but 2-5 is fine):

    An example of good indentation style, in C code:

    Code:
    //all lines in a function, are indented - they all are dependent to
    //the function they belong to.
    
    int main(void) {
       int i;
       
       for(i=0;i<14;i++) { //start of example for loop
          if(i < 7) {
             i+= 2;
             printf("i was incremented to: %d\n", i);
          }//end of if 
          else {
             ++i;
             printf("i was incremented to: %d\n", i);
          }  //end of else
       }//end of for loop
       return 0;
    }  //end of main()
    I'll post a better structured start to your program, later tonight.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is your program, with a few tweaks to make it more understandable.

    I don't recall how the game was played, but the complete logic for each round, should go inside the while() loop. If you use another function, then your call to the function goes inside the while() loop.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <time.h>
    
    double rand_mid(int low, int high)
    {
       return (double)(rand()%(high-low+1)+low);
    }
    
    
    int main(){
       long int a[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 b[26];
       int bripcase[11]={0,10,100,500,1000,5000,10000,50000,100000,200000,500000};
       int bcase[11]={0,0,0,0,0,0,0,0,0,0,0};
       int briefcase,remainingCase,choice,mainBriefcase;
    
    
       int ctr,ctr2,i,o,p,noDeal,roundNum,isWin,isLost;
       char *roundWord[11]={"","first","second","third","fourth","fifth",
          "sixth","seventh","eight","ninth","tenth"};
    
       srand(time(NULL));
       i = rand();
       o = rand();
       p = rand();
       
       for(ctr=0;ctr<26;ctr++) {  
          //again:
          b[ctr]=a[rand()%100];
          //for(ctr2=ctr-1;ctr2>=0;ctr2--){
            // if(b[ctr] == b[ctr2])
            // goto again;
          //}
       }
       printf("LET'S PLAY. . .\n");
       printf("\n*********************");
       printf("\n****    DEAL    *****");
       printf("\n****     OR     *****");
       printf("\n****   NO DEAL  *****");
       printf("\n*********************\n\n");
    
       for(i=0;i<10;i++) {
          if (bcase[i] ==0) {
             printf("[ %d ]\t\t",i+1);
          }
          else {
             printf("[   ]\t\t");
             printf("\n\n%d",bcase[i+1]);
          }
       }
       printf("\nSo what's your main briefcase? ");
       scanf("%d",&mainBriefcase);
    
       printf("You have chosen your briefcase.");
       printf("Press any key to continue...");
       _getch();
    
       isLost=0;
       isWin=0;
       roundNum=0;
       noDeal=1;
       remainingCase=9;
       while (remainingCase != 0 && noDeal == 1) {
          printf("\n\n\n deal or no deal %s round\n",roundWord[++roundNum]);
          printf("Offer of banker is %d, deal or no deal? 1 or 0\n", i);
          scanf("%d", &choice);
    
          printf("Please choose a briefcase: ");
          scanf("%d",&choice);      
     
          bcase[choice]=1; //0=not opened, 1=opened     
          
          //other logic here to finish out a round.
          
          
          
          if(roundNum>9) {
             isWin=1;
          }
    
          if(choice == 1 || isWin == 1)
          {
             printf("Thank you for playing the game ");
             printf("You've just won : %d", a[26]);
             _getch();
    
          }
       }
       return(0);
    }
    If you need to ask questions, ask away, but DON'T return your program back to the way it was. Learn to use C! We're glad to help.

  11. #11
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    Sir, after selecting a briefcase > all the other briefcase remaining should display> and I select 6 of the briefcases and they will show there value when opened. > then theres the offer and the question , DEAL or no deal? . you tweaked it wrongly >D:

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by dnates2012 View Post
    Sir, after selecting a briefcase > all the other briefcase remaining should display> and I select 6 of the briefcases and they will show there value when opened. > then theres the offer and the question , DEAL or no deal? . you tweaked it wrongly >D:
    Since I don't know the game, it would be difficult to tweak it and somehow, make it all that you need to play rightly.

    But the version of your program I posted, is still the right way to make your program -- you just need to add in the essential parts, into the while loop.

    The big difference is that now, the code is easy to alter, since it's 80% shorter, and it uses loops, instead of nasty goto's.

    So after the main briefcase is chosen (the first one), the player chooses 6 more briefcases, and after each choice, the value of the opened briefcases is shown.

    Only after the 6 briefcases have been opened, does the banker begin making offers, and any subsequent briefcase being opened causes the banker to make another offer?

    Then, of course, after every banker offer, there is the deal or no deal question. That makes sense, otherwise the banker's offer makes no sense.

    Does the banker offer include pennies, or just even dollar amounts?
    Same question for the briefcases - they're just even dollar amounts?

    I know you're tempted to go back to your old version of the program, but don't do it! This version can be easily modified to include everything needed. The old version can not.

    I'll see if I can find a little video of the game show, so I better understand the way the game is played, and make the display of the briefcases, work right.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    OK, I watched a video of the Deal or No Deal gameshow, on YouTube, and know the game. I'll update the version I posted above, to better fit the game.

    Hold fast with that newer version design, because updates are quite easy, now.

    I'll post up the newest version, in an hour or two. You'll see what I mean, then.
    Last edited by Adak; 09-16-2012 at 06:11 PM.

  14. #14
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    But aren't we supposed to help them write their own code, not write it for them?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by WaltP View Post
    But aren't we supposed to help them write their own code, not write it for them?
    In this case, the code he originally loaded was so poor that there wasn't enough patience in my soul, to allow working on it.

    So the options then, are to tell him to get stuffed, or help him with an example of something that would guide him along the right way. Tutorials would help, but clearly would be too slow to get anything turned in, even late. By the time he did that, he'd be so far behind the class, there's little difference to just telling him to straightaway, just get stuffed.

    I didn't know the game, so my first try to guide his program into something useful, was almost useless to him. The code was OK, but it just didn't apply to the game as it's played.

    In summary, some (especially new) posters need help above and beyond what I'd do for most posters. If they don't learn anything from it, that will be quite apparent in their subsequent posts.

    This is the revised version of the program. It has not been tested for accuracy, etc.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    #include <time.h>
    
    #define MAXCASE 27
    
    void showCases(long int a[26], int isOpen[26]);
    
    int main(){
       long int a[MAXCASE]={0,1,2,5,10,25,50,75,100,200,300,400,500,750,1000,5000,
          10000,25000,50000,75000,100000,200000,300000,400000,500000,750000,1000000};
       long int bankerOffer;
       int isOpen[27];
       int remainingCase,choice,mainBriefcase,toChoose;
       char chchoice;
    
       int i,j,deal,roundNum,sum,temp,youWon;
       
       for(i=0;i<MAXCASE;i++) {
          isOpen[i]=0;
       }
       
       srand(time(NULL));
       for(i=26;i>0;--i) {  //randomize the briefcase values
          j = rand() % (MAXCASE-1)+1;
          temp = a[j];
          a[j] = a[i];
          a[i] = temp;
       } 
       printf("\n");
       for(i=1;i<MAXCASE;i++ )
          printf("%7d ",a[i]);
       printf("\n");
       
       printf("LET'S PLAY. . .\n");
       printf("\n*********************");
       printf("\n****    DEAL    *****");
       printf("\n****     OR     *****");
       printf("\n****   NO DEAL  *****");
       printf("\n*********************\n\n");
    
       printf("\nSo what's your main briefcase? ");
       scanf("%d",&mainBriefcase);
       isOpen[mainBriefcase]=1;
    
       printf("You have chosen your briefcase.\n\n");
       printf("Press any key to continue...\n");
       _getch();
       
       bankerOffer=0;
       roundNum=0;
       deal=0;
       toChoose=6;
       remainingCase=MAXCASE-2;
       youWon=0;
       while (remainingCase != 0 && deal == 0) {
          printf("Welcome to round %d of Deal or No Deal\n",++roundNum);
          for(i=0;i<toChoose;i++) {
             printf("\nChoose your next briefcase to open: ");
             scanf("%d",&choice);
             printf("\nPlease open briefcase number %d: $%ld dollars\n",choice,a[choice]);
             isOpen[choice]=1; //0=not opened, 1=opened     
             showCases(a,isOpen);
          }
          remainingCase-=toChoose;
          --toChoose;
          printf("Now we'll see what the banker will offer. Here's the phone call now\a\a\a\n");
          sum=0;
          for(i=1,j=0;i<MAXCASE;i++) {
             if(isOpen[i]==0)
                sum+=a[i];
                j++;
          }
          bankerOffer = sum/j;
          printf("\nBanker is offering: $%ld dollars\n",bankerOffer);  
          printf("Now the question to you is: Deal, or No Deal [y/n]: ");
          scanf(" %c",&chchoice);
          getchar();
          if(chchoice=='y' || chchoice=='Y') {
             deal=1;
             youWon=bankerOffer;
          }
       }
    
       printf("Thanks for playing Deal or No Deal ");
       if(deal==0) {
          printf("You won %ld", bankerOffer);
       }
       else {
          printf("You won : %ld", a[mainBriefcase]);
       }
       printf("\nPrint Any Key to Continue\n");
       _getch();
    
    
       return(0);
    }
    void showCases(long int a[MAXCASE], int isOpen[MAXCASE]) {
       int i;
       printf("\n\n");
       for(i=1;i<MAXCASE;i++) {
          if(isOpen[i]==0) {
             printf("[ %2d ] ",i);
             printf("%7ld                ",a[i]);
          }
          else {
             printf("[ %2d ]                        ",i);
          }
          if(i%2==0)
             printf("\n");
       }
    }
    Very much off the cuff, actually. Again, I wouldn't ask for help with that old program, because it's really wacked to work with.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal arrays
    By shel5210 in forum C Programming
    Replies: 2
    Last Post: 03-31-2010, 01:40 AM
  2. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  3. Replies: 5
    Last Post: 09-18-2008, 02:57 PM
  4. "Deal or No Deal" Game
    By jaromdl in forum C++ Programming
    Replies: 13
    Last Post: 12-05-2006, 03:40 PM