Writing another program for school and I've got something seriously screwed with this one. I may have to post code for this, but I have my main function that calls another function(switcher), I'm trying to pass two arrays to this function and have that function switch the lowest value in one array replace it with the lowest value in the second array and vice versa. The problem is when I compile the program, it builds with no errors or warnings, runs up to the point where I call the function(switcher) then has some type of serious error at runtime and closes that window, and allows me to send an error report to microsoft. Any ideas what I'm doing wrong before I post all the code

general question regarding arrays and functions
Chan Chi Hang
This is the entire program, the error itself is when it runs into the call to the function "Switcher", somehow I have seriously messed up that funtion, if I comment out the call and the function it runs fine.
//Chapter 6 problem 24 page 249 (lab7)
#include <iostream.h>
#include <stdlib.h>
int seed=0;
void Fill_It(int []);
void Fill_It2(int []);
int Switcher(int [], int []);
int FindLow(int [] );
int main()
{
int i, array [20], arrayTwo[20];
cout << "\n Please enter value for seed 1.";
cin >> seed;
srand(seed);
cout << "\n Please enter value for seed 2.";
cin >> seed;
srand(seed);
Fill_It(array);
cout << "\n Array One"<<endl;
<< endl;
for(i=0; i<20; ++i)
{
cout << array
}
cout <<"\n Array Two"<<endl;
<< endl;
Fill_It2(arrayTwo);
for(i=0; i<20; ++i)
{
cout << arrayTwo
}
Switcher(array, arrayTwo);
return 0;
}
/*=====================================================================*/
void Fill_It(int array[])
{
=rand_num;
int i, rand_num;
for(i=0; i<20; ++i)
{
rand_num=rand()%1000;
array
}
}
/*=====================================================================*/
void Fill_It2(int arrayTwo[])
{
=rand_num;
int i, rand_num;
for(i=0; i<20; ++i)
{
rand_num=rand()%1000+1000;
arrayTwo
}
}
/*=====================================================================*/
int Switcher(int array[], int arrayTwo[])
{
int low_one=0, low_two=0;
int i, i_one, i_two;
for (i=0; i<20; ++i)
{
if (array
{
low_one=array
i_one=i;
}
if (arrayTwo
{
low_two=arrayTwo
i_two=i;
}
}
arrayTwo[i_two]=low_one;
array[i_one]=low_two;
cout << "\n Array One switcher"<< endl;
<< endl;
<< endl;
for(i=0; i<20; ++i)
{
cout << array
}
cout <<"\n Array Two switcher"<< endl;
for(i=0; i<20; ++i)
{
cout << arrayTwo
}
}
I'm not even sure if that function will operate correctly after I find out the main problem, but of course I can't figure out unless I correct this problem first.
ruds
Tony
TGA251
KvRaji
snap_ml
int i, i_one, i_two;
The problem is that these are not given default values and you use them as indexes.
Also, you should create variables as you need them, not all at the top of the function, unless you're using C instead of C++.
Stew2006
You're probably reading from or writing to a bad memory address.
Fili
Melbert
<iostream.h>
or
<iostream>
using namespace std;
std::cin; and std::cout;
Overall, does it matter which way I access the library
andyhoff
Van Vangor
Tony