This program isn't done, I know I'm just making a simple mistake. As you see in the void function from Lines 13-26, essentially I want the loop to be able print the values of my sector as (ex.) - (24,36,14), but when i run the program, it'll print (24,36, 321651327). Basically the last number will be what i presume to be the printed address. Is it perhaps because I'm not initializing a variable somewhere? I thought that by giving the value from my int(main), the function would know that the *n/*m pointer refers to what I inputted within the program, then print the nth value from the array.
#include <iostream>
usingnamespace std;
bool vect(int n, int m)
{
if(n==m)
return 1;
elsereturn 0;
}
void printvect (int *vec1, int *vec2,int*n,int *m)
{
for(int i=0;i<*n-1;i++)
{
cout<<vec1[i]<<" , ";
}
cout<<vec1[*n]<<endl;
for(int i=0;i<*m-1;i++)
{
cout<<vec2[i]<<" , ";
}
cout<<vec2[*m]<<endl;
}
int main()
{
int n=0;
int m=0;
cout<<"What are the dimensions for Vector 1?"<<endl;
cin>>n;
cout<<"What are the dimensions for Vector 2?"<<endl;
cin>>m;
if (vect(n,m))
{
int vec1[n];
int vec2[m];
cout<<"Enter the values for Vector 1."<<endl;
for(int i=0;i<n;i++)
{cin>>vec1[i];
}
cout<<"Enter the values for Vector 2."<<endl;
for(int j=0;j<m;j++)
{
cin>>vec2[j];
}
printvect(vec1,vec2,&n,&m);
}
elseif (!vect(n,m))
cout<<"The dimensions of your vector do not match."<<endl;
return 0;
}
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO, I just forgot, because essentially the 3 values that are representative of the array are vec1[0], vec1[1], vec1[2], it's only when you initialize is where you define the total values into the array, int vec1[3]. Then to print those values, it follows vec1[0], vec1[1], vec1[2]. Thank you Thank you hahah