Thread: Deal or No Deal arrays

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    6

    Deal or No Deal arrays

    I am attempting a deal or no deal game for a class. I have everything working, except for if the player wishes to review the remaining cash prizes.

    To start i have 2 arrays. One containing the prize values, and the other being the cases (filled at random with values from the prize array).

    I cannot display the remaining prizes directly from the cases array, as that would show what cases had what value. Instead, i must display them in increasing value, so as to hide their true order.

    Whenever i "open" a case the value is set to 0 in the cases array, but the prizes array is never changed. The problem is that if i open a case, this following function just outputs a blank line. What is wrong?

    Code:
    int prizelook (int cases[], int prizes[], int arraylength){
    
      int sentinal = 0;
      int i = 0;
      int j = 0;
    
      
      for (i=0; i<SIZE; i++){
      sentinal = 0;
      j = 0;
        while (sentinal==0){
          if (cases[j]!=0){
            if(prizes[i]==cases[j]){
            printf("$%d ", cases[j]);
            sentinal++;
            }
            else{
              j++;
            }
          }
          else{
          sentinal++;
          }
        }
      }
    
    
    }

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    If (cases[j]!=0) become false it will do nothing and comes out of for loop after SIZE iterations.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Whenever i "open" a case the value is set to 0 in the cases array, but the prizes array is never changed.


    Smacks me in the face as wrong. What good is a prize array if it's not being kept current? You could assign prizes without using a prize array, even easier.

    Use your prize array. Prize data should be found in the prize array. If the prize becomes unavailable, then set it to zero, for heaven's sake.

    As for this code. You need to throw in some printf's or watch on the variables, and make sure that your indeces and array values, are what you believe they should be.

    It's a very small nested loop, so step through it and see what's going on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to create and manipulate Terabyte size Arrays with Win32API
    By KrishnaPG in forum Windows Programming
    Replies: 1
    Last Post: 11-05-2009, 04:08 AM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. The deal with using 4d arrays :D
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2005, 02:28 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM