943,633 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6384
  • C++ RSS
Jul 26th, 2004
0

Find function

Expand Post »
Hi! I need help with the find function! I do not know how to use it in finding numbers.

For instance:
1 1 1 1 2 3 4 4 5 5 6 6 6 7 7 7 7

Using the find function, it will count the number of times a number appears.

1: 4 times
2: 1 time
3: 1 time
4: 2 times
5: 2 times
6: 3 times
7: 4 times

I need help with this, please! Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
biel_andrada is offline Offline
3 posts
since Jul 2004
Jul 26th, 2004
0

Re: Find function

Post some of your code.We could help out then.
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Aug 1st, 2004
0

Re: Find function

yeah .. this my assignment in the past .. try it .. it work fine ..
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. main()
  4. {
  5. //
  6. int array[10]={1,2,3,4,5,6,7,8,9,10};
  7. int left=0,right=9,middle;
  8. int number,i;
  9. bool sw=false;
  10. //
  11. cout<<"ARRAY: ";
  12. for (i=0;i<=9;i++)
  13. {
  14. cout<<array[i]<<";";
  15. }
  16. cout<<" \n"<<"Number to find: ";
  17. cin>>number;
  18. while (sw == false && left <= right)
  19. {
  20. middle=(left+right)/2;
  21. if (number == array[middle])
  22. {
  23. sw=true;
  24. cout<<"number found.\n";
  25. }
  26. else
  27. {
  28. if (number < array[middle]) right=middle-1;
  29. if (number > array[middle]) left=middle+1;
  30. }
  31. }
  32. if (sw == false) cout<<"number not found.\n";
  33. system("Pause");
  34. }
Team Colleague
Reputation Points: 55
Solved Threads: 3
Junior Poster
meabed is offline Offline
139 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C/Dos Programming
Next Thread in C++ Forum Timeline: compile error-chained hash table c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC