Adak 419 Nearly a Posting Virtuoso

My word, Thomas! You're running amok on us! ;)

Please set up your printed prompts for the user, just like the assignment asks for:
(one example):
Enter '(int * int) + (int / int) + (int % int)':

No reason to be knocked off on points for missing some gimme's.

In these example's there's only two numbers that need to be dealt with at a time, so I think you have a few too many variables, but I'll work up a little example, and see if my idea is right or not before suggesting it to you.

Using fgets and atoi is a good idea.

talk to you soon

Adak 419 Nearly a Posting Virtuoso

I want to generate 1billion random integer with no duplication, I dont know how do I allocate memory for such a huge amount of data.

This is a trick question, isn't it?

You've got a list of a billion unique random int's, stuffed in your back pocket, don'tcha?

You're trying to make us look silly, aren't you?

Well, as long as we're clear about that! ;)

If your random numbers are all positive (you didn't think of that, I bet!), then check your compiler for it's largest value of a long (or long long) unsigned int.

It may be in <limits.h> or <ctype.h>, but you can usually print it out with the macro MAX_LONGU, MAX_ULONG, or something like that.

That quantity will be the maximum amount you can (hope) to send out at a time, with this logic. You can do more using big char arrays of digits or big Number libraries.

I will stick to using neither, here.

So you've got your biggest integer. Now on your system, experiment a bit, and find out what is the largest array of TWO, of those big int's, that you can create.

One array will be an index, and the second will be the actual numbers to be sent out.

After generating the actual array full of random numbers, then initialize the index array, like so:

for(i = 0; i < MAX; i++)
  index[i] = i;

Then we'll sort the index, …

Adak 419 Nearly a Posting Virtuoso

You have to break out of the for loop, when i % 7 == 0, or the for loop will increment i another 2, and give you a wrong number.

I wonder why they have that feature in a for loop? Not a desirable one, imo.

Adak 419 Nearly a Posting Virtuoso

I'm thinking of:

First, find your lowN's lowest possible value lowN ^3 > 40000. Which may not be an equal number, or divisible by 7, either one.

then (I thought you might be able to increment this by 14, but that was incorrect. So scrap that idea.) ;)

if(lowN's lowest possible N is odd, then add one to it, so it's even)
then we're ready for a loop

haveIt assigned to zero //prime the for loop

for(i equals lowN; haveIt less than 1; i +=2) {
if(i % 7 is zero )
haveIt assigned value of 1;
}

Should do it. ;)

Adak 419 Nearly a Posting Virtuoso

I'd suggest using a for loop, and incrementing the number to be tested by 14, with each loop.

Put all your other tests that you need, right inside the for loop.

for(i = 0; i <=R; i+= 14) {
  //etc

}
Adak 419 Nearly a Posting Virtuoso

OX69's token approach is nice. Mine was more basic:

1) you test it for balanced parenthesis

2) start at the left side, "walk" char by char, until you reach the first right ).

Now walk back to the first left (. Everything in between is a balanced factor, so perform the indicated operation

((9-4)/(44*34))

9-4
5
And remove both of the inner parenthesis, so (5)/((44*34)) is left

now go right until you reach an operator (*/+-). When you reach it, you keep going into a new factor, ((44*34)), and repeat the same process you used for the first one.

You will wind up with a simple fraction (5)/(1496)

3) Again, walk through the factors, and test if any factor has more than one number in it. If it has no operators, then it has only one number.

So remove the parenthesis from both factors, and perform the division, as indicated: 5/1496

If your math expressions become more complex than this algorithm will handle, then switch to postfix notation or RPN. Those are quite robust.

When I say "walk" through the expression, I mean use a for loop and go through the string until you reach the end of string char: '\0', or other stopping point, in the algorithm.

for(i = 0; i < strlen(myMathStr); i++)  {
  if(myMathStr[i] == ')')
     //etc.

}
Adak 419 Nearly a Posting Virtuoso

1) Delete the pointers from your program. You don't need them, and they are now an impediment to making your program, run.

2) You can't use a variable, any variable, until you have assigned it a value:

argv[i]

When a variable is global (declared before main()), then OK, the variable will be assigned zero, by the compiler.

All other variables, like this i variable above, just has some left over garbage value, that will vary from one run of the program, to the next. Nothing you can count on here!

Assign all variables to 0, unless you know they will be assigned someplace else, before they're used. You can do it like this, if you want to. All these variables are int's:

var1 = var2 = var3 = var4 = 0;

and all these variables will be assigned a zero value.


I like the bubble sort code - very nice. ;)

Clean up the rest, and you'll have it.

Adak 419 Nearly a Posting Virtuoso

You're quite welcome. Odd thing about this bit of birthdays being on the same day - if you have a group of 50 people, the odds are VERY high that two of them will share the same bday.

Very un-intuitive! Google "Birthday paradox".

When I was in high school, I tried to explain this in an oral presentation to the class.

The presentation went well - but they didn't get it, at all.

Got me so mad, I went out to the field across the street, and kicked a brontosaurus in the butt, and ran like hell.

Ah, the good ol' days! ;)

Adak 419 Nearly a Posting Virtuoso

It can't sort right - read my earlier post.

Adak 419 Nearly a Posting Virtuoso

In your sort, you only have one loop.

for(k=0; k<N-1; k++)
           {
             if(a[k]>a[k+1])
               {
                  temp=a[k+1];
                   a[k+1]=a[k];
                   a[k]=temp;
                }
            }

Which you'd see in an instant, if it was properly indented:

for(k=0; k<N-1; k++)
      {
         if(a[k]>a[k+1])
         {
            temp=a[k+1];
            a[k+1]=a[k];
            a[k]=temp;
         }
      }

And there is only one sorting algorithm that uses one loop, and that is Gnome Sort.

If you want to do a bubble sort, you have to add the second for loop (you could use a while loop, but don't).

I know I'm probably spitting into the wind here, but I really hope you see how easy it is to spot problems with your code, when you indent it right, and change your indentation style. Right now, the words that come to mind to describe it, are pretty volatile and have a high percentage of 4 letters.

Adak 419 Nearly a Posting Virtuoso

He expressed no problem with the idea's I posted.

Messy marshes support far more life, than beautiful pristine forests.

Idea's need to be messy, sometimes.

Adak 419 Nearly a Posting Virtuoso

It was just some pseudo code to get him started on some idea's.

Must have been a fair idea, because your code uses them. ;)

Adak 419 Nearly a Posting Virtuoso
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main() {
  int VarA, VarB, Sum1;
  char op = '\0', ex;   //ex = extra char's
  VarA=VarB=Sum1 = 0;
  printf("Enter equation exactly as you see, inserting an INT for a, b, and c\n(a * b): \n");
  scanf("%c%d %c %d%c",&ex,&VarA,&op,&VarB,&ex);
  getchar(); //removes the newline from the keyboard buffer
  Sum1=VarA*VarB;
  printf("%d * %d = %d",VarA,VarB,Sum1);
  getchar();
  return 0; 
}
Adak 419 Nearly a Posting Virtuoso

No, I have to run errands and get off the computer.

It sounds stupid, but the computer is very stupid with stuff like this. If you know how to make stacks, you can use them, here. See Wikipedia for postfix and RPN.

If not, "walk" in from left to right, until you hit the first RIGHT ), Then back up until you hit the first (. The expression in between should be "balanced" and just walk to the right again, and do the indicated operation (add, subtract, whatever).

Then continue on, and do the same for the next factor in the expression.

Sorry to talk "math speak", but believe me, I'm not a math person. My math teachers will swear to that! ;)

Adak 419 Nearly a Posting Virtuoso

That's one of the kinds of errors that you won't find without your code being properly indented.

I couldn't do it by looking at your code, because it's all over the place in it's indentation style.

Here's how to fix it:
Open up Turbo C and click on "Options", then "Environment", then "Editor".

In the list of Editor Options, uncheck the [] Use tab character box.
Check the [X] Use Autoindent mode, just above that.

Below that list, put in 3 for Tab Size, and tell it to use C for the default compiler.

Then use three spaces for every level of indentation in your code. Be consistent. 2 to 4 spaces, for indentation, is ideal.

Tab char's show up badly on all programming forums I've been to, so use spaces in your code.

Oh yeah! Some code:

#include <stdio.h>

int main() {
  int num,i, j;
  num = 2;
  while(num % 2 == 0) { //
    printf("\nenter any odd num");
    scanf("%d",&num);
    getchar(); //not essential, but good.
 }

 //c'mon, this is C, we count "zero, one, two...", unless there's a
 //good reason for starting elsewhere, start at zero.

  for(i=0;i<num;i++){ //for every row of *'s
    printf("\n");
    if(i % 2 == 0) { //if the row is even
    for(j=0;j<num;j++) //print num stars
      printf("*");
    }
    else { //row is odd C odd ;)
      for(j=0;j<num;j++){
        if(j ==0 || j == (num-2)) {
          printf("*");
        }
        printf(" ");
      }
    }
  }
  getchar();
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

I'm sure you didn't.

Post your latest code, and let's see what's up with it.

Adak 419 Nearly a Posting Virtuoso

Looks good to me.

Now start from the beginning of the string, find the innermost set of parenthesis, and perform the indicated operation.

I mean, reduce each part of the expression, by one level.

Then reduce it by another level, and you're done.

Adak 419 Nearly a Posting Virtuoso

OK, the change will be right in this part of the code:

else {                //row is odd  C odd ;)
      printf("* *");
    }

you need to add a for(j = 0, j < num; j++) loop right below the "else", line, and change the printf(), so it prints just one *.

Inside the for loop I just mentioned, you need an if statement:

if(j ==0 || j == (num-2)) {
     print a *
   }
    print a space: " "

So that leaves you with a little coding to do, but you should be able to sort that out, in short order.

Adak 419 Nearly a Posting Virtuoso

remove the commas from your scanf() line of code

Adak 419 Nearly a Posting Virtuoso

I'm sure your compiler is OK.

Just show what you want, and use code tags (and be careful, because it shows odd spacing until you post).

Adak 419 Nearly a Posting Virtuoso

I wrote that using Turbo C compiler and it does what I thought you wanted:

for user enters 5:

*****
* *
*****
* *
*****

Do you want spaces between each star in the row of 5?

Do you want to draw a box of stars with rows of stars in the middle of it?

*****
*   *
*****
*   *
*****
Adak 419 Nearly a Posting Virtuoso
#include <stdio.h>

int main() {

  int num,i, j;
  num = 2;
  while(num % 2 == 0) {
    printf("\nenter any odd num");
    scanf("%d",&num);
   getchar();  //not essential, but good.
 }

  //c'mon, this is C, we count "zero, one, two...", unless there's a
  //good reason for starting elsewhere, start at zero.

  for(i=0;i<num;i++) {  //for every row of *'s
    printf("\n");  
    if(i % 2 == 0)  {     //if the row is even
      for(j=0;j<num;j++)  //print num stars 
         printf("*");
    }
    else {                //row is odd  C odd ;)
      printf("* *");
    }
  }
  getchar();
  return 0;
}

M, don't post multiple threads next time - it's frankly confusing and irritating, and keep a good attitude. You are asking for a favor.

And always use code tags!

I (and others), won't help any more if you don't follow forum rules, and you might even be banned.

Adak 419 Nearly a Posting Virtuoso

Seems like you could scanf() and get a number from the user

and then use a for loop to print out the lines of *'s, alternating between the user's number of *'s, and two *'s.

So every time your iterator in the loop is even, you want the user's number of *'s, and when the iterator is odd, you want just two *'s.

i % 2 == 0 is a very good test you might use, to see if the iterator i is even or not.

Give that a try and post up your code.

AND USE CODE TAGS AROUND YOUR CODE - ALWAYS

Adak 419 Nearly a Posting Virtuoso

An outline in pseudo code:

char map[10][10]
char myString[12]

for(each row) {
  
  fgets(myString, 10, filePointer);
  k = 0
  for(each column in the row) {
     map[row][col] = myString[k++]
  }  
}
jephthah commented: sorry man, that's just sloppy. -1
Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Rinku! :)

In the editing (advanced) window, whenever you post code, highlight it, and click on the [code] icon at the top of that window. The idea is to surround your code with these code tags.

That makes your code, stay looking like code, instead of being all squashed to the left side.

I wouldn't bother posting a C++ solution to a C assignment or question. These are coders (mostly students), who are taking a C class, and know very little/nothing yet, about C++, and can't turn C++ code in for credit, anyway.

Save the C++, for the C++ questions.

Adak 419 Nearly a Posting Virtuoso

Hosam, why don't you read up on that topic at Wikipedia or in your text or class notes, and apply it into a program.

What you want to do is find out when you have it working right, and have something you can copy, and keep it as a reference if needed, later.

I'm having some trouble understanding what you mean by "half half", etc. also.

Adak 419 Nearly a Posting Virtuoso

It keeps showing me an error for this line:

int bdays[g] = { 0 };

How this is handled, depends on what version of the Standard for C, you're compiler is supporting.

Usually, g would need to be a constant int, declared before that line (of course), or a (capitalized by convention):
#define G 300

(for the number, pick one about twice the size of what you expect your largest number of guests to be.)

located just below your #include files lines of code (also by convention).

You CAN allocate the exact size of array you want with malloc, but your class hasn't got there yet - otherwise you wouldn't be showing me this error.

Then make it:
int bdays[G] = { 0 };

and remember to keep the lower case g, for whatever the user inputs as the number of guests.

So the teacher's intention is to show malloc to you, later. I would use #define G 300 for now.

Adak 419 Nearly a Posting Virtuoso

"So freakin' close!"

Yep! ;)

I see you're determined to do this the simple and slow way <sigh >

int party(int g) {
  int i, j, bdnum; 
  int bdays[g] = { 0 };
  long int parties, hold;
  for(i = 0; i < g; i++)  {
    bdnum = 1 + rand() % 365;
    for(j = 0; j <= i; j++)  {
      if(bdnum == bdays[j])  
        return 1;
    }
     //assign bdnum to bdays[i], here 
  }
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Also there are some nonsensical code here - what is this ?

else
   i - 1;

??
But i dont like brute-force search as I said before, because it will perform slow. So you should try to search for duplicates as in my example before OR at least:
1. Sort bdays array with QSORT function.
2. Then search that bdays array in acending order with only one loop, something like

// sort bdays
qsort(bdays,...);
// search for duplicates
// (this only do AFTER you generate ALL guest birthdays)
for (j = 0; j < g-1 ; j++) {
   if (bdays[j]==bdays[j+1]) {
    // duplicate found
    return 1
   }
}
// there are no duplicates
return 0;

In this case sorting array + 1 loop should perform faster than performing 2 loops as in your code. But ... as you wish.

Good luck!

As it turns out, the assignment requires LM to NOT have duplicate bdays checked after they've been assigned to all the guests.

I thought it would simplify the program a bit to do it that way. Also, it just seemed odd to check bdays BEFORE they were assigned to the guests.

Bottom line is, it will be done (with the next version), using a very fast counting sort look up, BEFORE the bdays are assigned. So it will be way faster than Quicksort or any other sorting algorithm.

If you haven't run across the simplicity and speed of counting sort, you might want to stay …

Adak 419 Nearly a Posting Virtuoso

Unfortunately, he took it to mean remove it, so he did. ;)

Didn't mean to step on your post. Go ahead and finish him off, RB.

Adak 419 Nearly a Posting Virtuoso

Oh says the smart student, I could put that counting sort code just before the assignment of the random number bday!

Brilliant!

if(counting sort finds a duplicate)
return value to indicate a duplicate was found
else
assign bday number to the guest


return value to indicate no dupes were found

You could do a binary search instead, before the bday assignment, but that's about 800% slower. A sequential search would be Number of guests * 100 % slower. < eek! >

Adak 419 Nearly a Posting Virtuoso

You should keep the void search(), and delete the int search(). Just add some logic into the search() function you already have.

Removing the newline was a good idea. I'd keep that old line #11.

How about printing up a prompt like this:

"Enter a char to search for, or 0 for general string information: "

then
scanf() same as now.

Then, in search()
if(charTheyEnter == '0')
get strlen();
get any other info you need for general search and print it
}
else {
//code in here for specific char searching
}

Adak 419 Nearly a Posting Virtuoso

Line 11 overwrites the newline char from the char name[].

Your search function has two types of searches:

1) for a specific char, and
2) for general info on the entire string.

So how about passing a '0' (zero) char, for a general, non-specific search, and anything else could be the specific char to be searched for.

So your search() declaration could be:
void search(char *name, char target)

Where target is what you're looking for, unless it's a '0' char.

The search() function will need the name of the array to be searched - "name", in your program.

and lastly, search() needs to know the specific char it is searching for, if the search is for a specific char.

C has a built in searcher for a char in a str, called strchr(). Part of the string.h file, which you'll need to include.

It's also very easy to "roll your own" by using a for loop, and "walking" the char's in the array, and counting the data you need, as you go, and printing it when the for loop is over.

Either way, up to you.

Adak 419 Nearly a Posting Virtuoso

Ok, well the code is doing exactly what i want it to do except for one minor thing. It is always returning 1. I'm thinking there is something wrong with the for loop when I am comparing bday and bday[j].


#include <stdlib.h>
#include <time.h>
int party(int g);
main()
{
      int guests, j;
      long int parties, samebday, diffbday, count;
      printf("Enter the number of parties: ");
      scanf("%ld", &parties);
      printf("Enter the number of guests: ");
      scanf("%d", &guests);
      srand(time(NULL));
      samebday = 0;
      diffbday = 0;
      for (j = 1; j <= parties; j++)
      {
      count = party(guests);
      if (count == 1)
         samebday++;
      else
          diffbday++;
      }
      printf("%d \n", samebday);
      printf("%d \n", diffbday);
      system("PAUSE");
      return 0;
}
       
      int party(int g)
{
      int i, j, bdays[g];
      long int parties;
       for(i = 0; i < g; i++)
       {
             bdays[i] = 1 + rand() % 365;
       for (j = 0; j < g; j++)
       {
          if (bdays[i] == bdays[j])
             return 1;
             else
                 i - 1;
             if (i == 0)
                return 0;
       }
       }
}

As WaltP has alluded to, the party() loops are off.

I think you were thinking about the nested loops needed in main:

1) for the parties, and 2) for the guests.

But in the party() function, there is no need for nested loops. There is only "guests" data from one party at a time, present.

So the for loop with j as the iterator, should be removed, completely.

...//your other code in party() up here, 

    for(i = 0; …
Adak 419 Nearly a Posting Virtuoso

Another point I did not mention, but is very likely to cause errors, is if you re-use the dupes array, after one party, without resetting the elements of that array to zero!

That would give you VERY large numbers, after a bunch of parties. So set it to zero's, using a for loop, after every party has been all reported.

Adak 419 Nearly a Posting Virtuoso

Assignment of a value to a variable, uses just ONE = sign.

Comparison of one variable with a number, requires TWO == signs.

So this needs correcting in your code:

samebday == 0;  //***
      diffbday == 0;    //***
      for (j = 1; j <= parties; j++)
      {
      count = party(guests);
      if (count = 1)    //***
         samebday++;
      else
          diffbday++;
      }

All the one's with //*** on that line, need correcting.

Check the rest of your program over for more of the same. I did not do that.

Adak 419 Nearly a Posting Virtuoso

I can't fix code that I can't see. ;)

Adak 419 Nearly a Posting Virtuoso

Sure there is!

You can use strchr() to look for a char in the string, or strstr() to look for a sub string in the string, same as if your char array was outside the struct.

There is no difference, except you need to use the dot operator to access the struct member:

#include <stdio.h>
#include <string.h>  //needed for strstr() or strchr()

struct myStruct{
  char firstName[20];
  int age;
  //etc.
}mystruct1;

int main() {
  //using the dot operator for a simple char array print:
  printf("\n%s ", mystruct1.firstName); 
  return 0;
}

If you're stuck on this, post up your code, and let's see what you're stuck on.

Adak 419 Nearly a Posting Virtuoso

It was crashing because you were running outside the boundaries of dupes. It has to have 366 elements (0-365). Even though there is no day 0, the arrays in C always start with zero, so that explains the one day extra in this size (I hope). ;)

The program is a bit odd, because the party() function does everything. I did not change that.

#include <stdio.h>


int party(int g, int p)
{
      int guests, count, i, j, duplicates[366] = { 0 }, k, haveDupes = 0;
      int bdays[10] = {209,37,209,151,37,302,8,142,151,209};
      long int parties;
      guests = 10;
/*      printf("Enter the number of parties: ");
      scanf("%ld", &parties);
      parties = 1;
      printf("Enter the number of guests: ");
      scanf("%d", &guests);
      guests = 10;
      for (j = 0; j < parties; j++)
      {
*/
        for(i = 0; i < guests; i++)
        {
//          bdays[i] = 1 + rand() % 365;
            duplicates[bdays[i]]++;
            if(duplicates[bdays[i]])
              haveDupes = 1;
        }
    //}


      if(haveDupes) {
        printf("\n The Duplicated Birthday Numbers Are: \n");
        for (k = 0; k < 366; k++)
        {
          //printf just to test
          if(duplicates[k] > 1)
             printf("\n%3d: %5d", k, duplicates[k]);
        }
      }
      else
        printf("\n No Duplicated Birthday Numbers Were Found.");

}
int main() {
  int n;
  printf("\n\n");
  n = party(0,0);  

  getch();
  return 0;
}

variables like g, p, and n (in main), are never used and shout that the program needs a bit of a re-design, when you can.

To enable multiple parties, just remove the /* and */ from your code, and be sure the …

Adak 419 Nearly a Posting Virtuoso

Back in a bit.

Adak 419 Nearly a Posting Virtuoso

Strings don't need to be returned from a function.

When you send a string to a function (which is what you want to do), you are sending a constant pointer (which is the name of the char array, itself).

And since the function has the address, rather than just the variable itself( like a number would be), then it can make changes into the char array, (the string).

#include <stdio.h>

void changeIt(char *mystring) {
   mystring[2] = 't';  
}


int main() {
  char mystring[10] = { "Ack!" };
  
  changeIt(mystring);
  printf("\n%s", mystring);

  return 0;
}

So normally, you want to bring the array name into the function that will be working on it. Local arrays from the function itself, will terminate after the function executes - so trying to use it afterward is an error - sometimes you get away with it, but static local arrays, can't be trusted to work right, after their function is done.

Adak 419 Nearly a Posting Virtuoso

After the for loop for each party, you want use the "follow closely" code, to find the elements in dupes, if any, that have a value greater than 1.

Those are your duplicated bdays.

Read that part again, and use that "counting sort" logic, in your program. You'll be glad you did.

Adak 419 Nearly a Posting Virtuoso

Didn't you forget the rule about "Must not use any cpu cycles"? ;)

Adak 419 Nearly a Posting Virtuoso

Then you should Google this up, and see what is the best algorithm to use for this. To solve puzzles like this, I use DFS and logic, and that's it, with rare (very rare), exceptions.

When it comes to run-time, I use the "one sip" rule:
If the program is done in the time it takes me get one sip of a beverage, then I'm completely happy, and don't give a rat's patootie about it's BIG O complexity.

I have a program that processes about 500,000 records, and I don't care if it takes it 12 seconds to do it. It gets the 2 sip rule. ;)

Anyway, check around. This is an old puzzle, so I'm sure there's some info on the best algorithm to use for it, someplace on the net.

I have looked into how my program moves the tiles, and it certainly is not making the least number of moves, so that's bad. On the good side though, it doesn't spend hardly any time trying to search through a large search tree, looking for how to move next.

I haven't seen that program in awhile, so I'll have to dig it up.

See J! That's where I need the Zombies! Nobody digs up the dead, like Zombies dig up the dead! ;)

Google around and see what a good algorithm is for this, (I wouldn't recommend BFS for this).

ttyl

Adak 419 Nearly a Posting Virtuoso

Well, J, I thought they were people.

You thought they were Zombies.

Now, I guess they were ghosts - gone from this thread, like magic.

And they say the paranormal is a bunch of hokum! ;)

Adak 419 Nearly a Posting Virtuoso

Lol, that makes a lot more sense than float. Thank you.

Making the array is one of my problems. I'm not quite sure how to set the value inside the array to the number entered by the user. Every time I try something the compiler gives me an error. And I am also unsure how to scan the random number into the array.

You make an array like any other variable, but add [SizeYouWant] after the name of the array. This is a static array - not the only kind, btw.

Use the index to the array's elements, to set your bday numbers up

And on further thought, the easier way to do this is with "counting sort".

Follow me closely:

In the array of numbers {1,3,1,4}, I want to know if there are any duplicate numbers.

I make an array

int dupes[5] = { 0 };  //set array to all zero's
//size is one number bigger than the largest value in numbers!

and then do a for loop like this:
for(i = 0; i < 5; i++) {
  dupes[numbers[i]]++;
}
Now, the dupes array will look like:
Index numbers:
   0  1  2  3  4
==============
{ 0, 2, 0, 1, 1 }

Now, in a simple for loop, I can see if any of the dupes array elements have a value greater than 1. If they do, then there was a duplicate in numbers[] (bdays to you).

This is a simple, and …

Adak 419 Nearly a Posting Virtuoso

Yes, everybody except those condemned to Hell.

They have to use "Brainluck" language. ;) ;) (but with an f in place for the l letter)

Wikipedia search it for a laugh.

Adak 419 Nearly a Posting Virtuoso

Still wrong - use long int, and your range will be no problem.

Seriously, don't use floats EVER if you don't have to. Try to print out ten and one-third to see one reason why, on your double or float.

Adak 419 Nearly a Posting Virtuoso

Right off the bat, I don't like float data types for parties and bdays. No one has 1/4th of a party, or .01 bdays.

Unless there is a specific need for floats or doubles, don't use them! They have their own subtle problems.

You will need two nested loops:

for(each party)  {
   for(each guest)  {
      assign their bday. maybe put it also into an array of int's
   }
   now all guests have bdays, see if any of them are duplicate days
   maybe sort them out, and they will be adjacent in the sorted list?
   if (number of duplicates you find > 0)
      return 1
   else
      return 0
  }

That kind of idea.

And welcome to the forum! :)

P.S. If you make your outer loop inside the party function, aren't you going to be stuck trying to return something like your assignment requires?

I would move those questions, and that loop, to main, and use party() as a call, inside that loop.

Adak 419 Nearly a Posting Virtuoso

Sure! Why not?

Here's the thing -- you have to contribute idea's and sometimes, code into this. I'm not going to just post up a program for you, and I hope you don't want to be a "code leech".

So, what does your instructor say to use for an algorithm to solve this? No sense posting on and on about Depth First Search (DFS), if your instructor wants you to use another type of search.

So what, Arshad and Lucy, does your instructor, require for this assignment? What does he suggest you use?

And post up some code, that shows you have some "skin" in the program.

I use DFS for about everything, (and know very little about other types of searches), but others may be along with a broader knowledge, to match your needs.

Welcome to the forum: Arshad, Aliakseis, and Lucy! :)