i want to create a program that will have an arraycalled array1[] of 30 sets of 3 one digit numbers i.e 804, 450,430 etc)

i will have 13 vector containersor arrays defined with a series of 3 one digit numbers. i want the program to find any series of numbers that is array1[] in any of the 13 vectors. and it will tell me in which vector the series was found in

also the order of the number shouldnt matter for example vector<int> first_tier (324)

the user enters 243 or 432 and it finds it in first_tier because 324 is 243 just in differn't order. so which function do i use to do this. this is what i got so far

// Pick 3 Probablity

#include<iostream>
#include <vector>
#include <algorithm>


using namespace std;



int main()

{
    // the series of numbers  to be found in the vectors below
    int previous_pick_3_numbers[20]{346,794,861,529,347,925,196,969,243,837,740,025,822,809,454,843,942,510,573,346};
  // 13 vectors
    vector<int> firsts_tier(409 , 508 , 509, 607, 608 ,707 , 139 , 148 , 149 , 157 , 158 ,166 , 167 ,229 , 238 , 239 ,247 , 248 ,256 ,257 ,266 ,337 ,338 ,346 ,347 , 355 , 356 , 445 , 446 ,455);
    vector<int> seconds_tier(309 , 408 , 507 , 606 , 609 ,708 ,129 ,138 , 147 , 156 , 159 ,168 ,177 , 228 , 237 , 246 , 249 , 255 , 258 , 267 , 336 , 339 , 345 , 348 , 357 , 366 , 444 , 447 , 456 , 555);
    /*vector<int> thirds_tier(209,308,407,506,709,808,119,128,137,146,155,169,178,227,236,245,259,268,277,335,344,349,358,367,448,457,466,556);
    vector<int> fourths_tier(208,307,406,505,809,118,127,136,145,179,188,226,235,244,269,278,334,359,368,377,449,458,467,557,566);
    vector<int> fifths_tier(900,108,207,306,405,909,117,126,135,144,189,225,234,279,288,333,369,378,459,468,477,558,567,666);
    vector<int> sixths_tier(800,107,206,305,404,116,125,134,199,224,233,289,379,388,469,478,559,568,577,667);
    vector<int> sevenths_tier(700,106,205,304,115,124,133,223,299,389,479,488,569,578,668,677);
    vector<int> eighths_tier(600,105,204,303,114,123,222,399,489,579,588,669,678,777);
    vector<int> ninths_tier(500,104,203,113,122,499,589,679,688,778);
    vector<int> tenths_tier(400,103,202,112,599,689,779,788);
    vector<int> elevenths_tier(300,102,111,699,789,888);
    vector<int> twelves_tier(200,101,799,889);
    vector<int> thirteenths_tier(100,899,999); */
    
    bool myfunction (int i,int j) { return (i<j); }


  
  vector<int> copy_of_array(previous_pick_3_numbers,previous_pick_3_numbers+20);                         // 1 2 3 4 5 4 3 2 1

  // using default comparison:
  sort (firsts_tier.begin(), firsts_tier.end());

 
  if (binary_search (firsts_tier.begin(), firsts_tier.end(), copy_of_array;))
    cout << "found!\n"; else cout << "not found.\n";

  // using myfunction as comp:
  sort ( firsts_tier.begin(),  firsts_tier.end(), myfunction);

  cout << "looking for a ... ";
  if (binary_search (seconds_tier.begin(), seconds_tier.end(), copy_of_array, myfunction))
    cout << "found!\n"; else cout << "not found.\n";
    
    return 0;
}

i get lots of errors

Line 16 is missing an equals sign...

int previous_pick_3_numbers[20] ={346,794,861,529,347,925,196,969,243,837,740,025,822,809,454,843,942,510,573,346};

Line 32 is a function inside of another function. You can't do that in C++. Try moving line 32 to line 10.

With those two errors, the compiler will get confused and give you hundreds of errors that aren't actually really errors. Try making those two changes and re-compiling.

i did the changes, but i still get lots of errors. its been 2 years since i last coded in c++

i get erros like 16 C:\Documents and Settings\fpadilla\My Documents\Pick3.cpp no matching function for call to `std::vector<int, std::allocator<int> >::vector(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)'

Try creating arrays for all of them and then creating the vector from the arrays like you do in lines 16 and 36. Remember to add the = sign to line 16.

int firsts_tier_numbers[30] = {409 , 508 , 509, 607, 608 ,707 , 139 , 148 , 149 , 157 , 158 ,166 , 167 ,229 , 238 , 239 ,247 , 248 ,256 ,257 ,266 ,337 ,338 ,346 ,347 , 355 , 356 , 445 , 446 ,455};
vector<int> firsts_tier(firsts_tier_numbers,firsts_tier_numbers+30);

ok i did some changes.

i still get errors. But less errors now. here is the code. The green text is where one error is. the error says 53 C:\Documents and Settings\fpadilla\My Documents\Pick3.cpp instantiated from here

#include<iostream>
#include <vector>\
#include <algorithm>


using namespace std;

bool myfunction (int i,int j) { return (i<j); }

int main()

{
    // Arrays that will be copyed into vectors below.
int one[]={409 , 508 , 509, 607, 608 ,707 , 139 , 148 , 149 , 157 , 158 ,166 , 167 ,229 , 238 , 239 ,247 , 248 ,256 ,257 ,266 ,337 ,338 ,346 ,347 , 355 , 356 , 445 , 446 ,455};
int two[]={309 , 408 , 507 , 606 , 609 ,708 ,129 ,138 , 147 , 156 , 159 ,168 ,177 , 228 , 237 , 246 , 249 , 255 , 258 , 267 , 336 , 339 , 345 , 348 , 357 , 366 , 444 , 447 , 456 , 555};
/*int three[]={209,308,407,506,709,808,119,128,137,146,155,169,178,227,236,245,259,268,277,335,344,349,358,367,448,457,466,556};
int four[]={208,307,406,505,809,118,127,136,145,179,188,226,235,244,269,278,334,359,368,377,449,458,467,557,566};
int five[]={900,108,207,306,405,909,117,126,135,144,189,225,234,279,288,333,369,378,459,468,477,558,567,666};
int six[]={800,107,206,305,404,116,125,134,199,224,233,289,379,388,469,478,559,568,577,667};
int seven[]={700,106,205,304,115,124,133,223,299,389,479,488,569,578,668,677};
int eight[]={600,105,204,303,114,123,222,399,489,579,588,669,678,777};
int nine[]={500,104,203,113,122,499,589,679,688,778};
int ten[]={400,103,202,112,599,689,779,788};
int eleven[]={300,102,111,699,789,888};
int twelve[]={200,101,799,889};
int thirteen[]={100,899,999};*/

// array that will be compared from
int previous_pick_3_numbers[20]={346,794,861,529,347,925,196,969,243,837,740,025,822,809,454,843,942,510,573,346};

   vector<int> pick3(previous_pick_3_numbers,previous_pick_3_numbers+20);
   vector<int> firsts_tier(one,one+30);
   vector<int> seconds_tier(two,two+30);
    /*vector<int> third_tier(three,three+28);
    vector<int> fourths_tier(four,four+26);
    vector<int> fifths_tier(five,five+24);
    vector<int> sixths_tier(six,six+20);
    vector<int> sevenths_tier(seven,seven+16);
    vector<int> eighths_tier(eight,eight+14);
    vector<int> ninths_tier(nine,nine+10);
    vector<int> tenths_tier(ten,ten+8);
    vector<int> elevenths_tier(eleven,eleven+6);
    vector<int> twelves_tier(twelve,twelve+4);
    vector<int> thirteenths_tier(thirteen,thirteen+4); */
    
    


  
  // using default comparison:
  sort (firsts_tier.begin(), firsts_tier.end());

  if (binary_search (firsts_tier.begin(), firsts_tier.end(),pick3))
    cout << "found!\n"; else cout << "not found.\n";
  

  // using myfunction as comp:
  sort ( firsts_tier.begin(),  firsts_tier.end(), myfunction);

  cout << "looking for a ... ";
  if (binary_search (seconds_tier.begin(), seconds_tier.end(), pick3, myfunction))
    cout << "found!\n"; else cout << "not found.\n";
    
    return 0;
}

Thanks again for your help

I can't explain the exact cause of your error message or why it complains the way it does. I can tell you that binary_search() takes either 3 or 4 parameters. The first is a location to start, the second a location to stop, the third is a single value to look for, and the fourth (if there is one) is a function used to compare two elements in the container being serched if the < operator is not to be used (the < operator is the default comparitive operator).

pick3 appears to be declared as a vector of ints, not a single int value as expected by binary_search(). So in the line you pointed out, I would have expected an error to the effect "cannot convert vector<type T> to type T".

If you can find an error in the line pointed out by the compiler (or one shortly before the line pointed out sometimes), fix it and recompile, even if you aren't sure what the compiler is trying to say. In my experience it works more often than not.

Edited 5 Years Ago by Lerner: n/a

This article has been dead for over six months. Start a new discussion instead.