0

I have a problem with this program

#include <iostream> using namespace std; const int dim_max = 100; struct Data { int g, m, a; }; bool ricerca(Data *v[], int n, Data d) { for(int j=0; j<n; j++) { if(v[j]->g==d.g && v[j]->m==d.m && v[j]->a==d.a) return true; } return false; //it must to give true if it is in the array, else false. }; int main() { Data d1[dim_max]; Data *A[dim_max]; int i=0; cout<<"Insert the date (max 100)(0 to terminate)"<<endl; while(i<dim_max){ cin>>d1[i].g; if(d1[i].g==0) break; cin>>d1[i].m; cin>>d1[i].a; A[i]->g = d1[i].g; A[i]->m = d1[i].m; A[i]->a = d1[i].a; i++; } Data d; d.g=15; d.m=8; d.a=1994; if(ricerca(&A[dim_max],i,d)==true) cout<<"The date is in the array."<<endl; else cout<<"The date is not in the array"<<endl; system("pause"); return 0; }

14th Sep 2019, 7:26 PM
Eden
Eden - avatar
3 Answers
+ 1
Thanks, I corrected the errors and works perfectly.
14th Sep 2019, 9:40 PM
Eden
Eden - avatar