Excercise c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Excercise c++

Given two incoming vectors with their fillings r1 and r2. For each element of the first vector, check if it is greater than the first element of the second vector. If it is greater then insert it in a third carrier. Print a third vector with the possible elements, if no element of the first vector is greater than the first element of the second vector, print a suitable message. #include<iostream> #include<stdlib.h> using namespace std; const int MAX_ELEM=150; void input(int [],int [],int &,int &); bool find(const int [],const int [], int[],int ,int ,int ,int &); void output(int [],int ); int main(){ int V1[MAX_ELEM]; int V2[MAX_ELEM]; int r1,r2,val,pos; input(V1,V2,r1,r2); trova(V1,V2,V3,r1,r2,r3,pos); if(trova(V1,V2,r1,r2,pos)) output(V3,r3); else cout<<"Don't exist any values'"; return 0; void input(int V1[], int V2[], int &r1, int&r2){ int i=0; do{ cout<<"Insert r1 of ARRAY 1: "; cin>>r1; if((r1<0)||(r1>150)) cout<<"Respect the parameter (MAX "<<MAX_ELEM<<" ELEMENTS)\n"; }while((r1<0)||(r1>150)); do{ cout<<"Insert r2 of ARRAY 2: "; cin>>r2; if((r2<0)||(r2>150)) cout<<"Respect the parameter (MAX "<<MAX_ELEM<<" ELEMENTS)\n"; }while((r2<0)||(r2>150)); for(i=0;i<r1;i++){ cout<<"(ARRAY 1) Insert element "<<i+1<<" : "; cin>>V1[i]; } for (i=0;i<r2;i++){ cout<<"(ARRAY 2) Insert element"<<i+1<<" : "; cin>>V2[i]; } } bool find(const int V1[],const int V2[],int V3[],int r1,int r2,int r3,int &pos){ int i=0; int j=0; bool finded=false; for (i=0;i<r1;i++){ while((i<r1)&&(!finded)){ if(V1[i]>V2[j]){ finded=true; val=V1[i]; } else i++; } } return trovato; I stopped here because i know who i wrong the function find help me plss

26th Jun 2019, 6:59 PM
Domenico Carrano
Domenico Carrano - avatar
1 Answer
+ 1
Why are you using arrays instead of vectors? you have not declared 'V3', 'r3' and 'trova' you can't declare a function inside main after "return 0" >> (line 23) what is "return trovato;"? https://code.sololearn.com/c66c00x4Z7US
29th Jun 2019, 12:44 PM
Mina Yossry
Mina Yossry - avatar