I'm REALLY confused. Why isn't cout or cin working here?
I'm creating a program that fills arrays with random numbers, then sorts them in ascending and descending order. I have no problem with that. My question is, why am i getting errors that cout and cin are undeclared in my code. I try using #include <iostream>, but that gives me an even longer list of errors. Here's my code: (Thanks for reading)
Code:
#include <cstdlib>
#include <iomanip>
using namespace std;
const int SIZE = 200;
void initialize_array(int random_ints[], int num_elements, int bound);
int main(void)
{
int original_data[SIZE];
int copy_data[SIZE];
int num_values = 0;
int bound = 0;
cout << "Number of random data values in array (0-200)? ";
cin >> num_values >> endl;
cout << "Bound on maximum value? ";
cin >> bound >> endl;
return 1;
}
void initialize_array(int random_ints[], int num_elements, int bound)
{
int seed_value = 0;
cout << "Random seed value? ";
cin >> seed_value >> endl;
srand(seed_value);
for(int i = 0; i < num_elements; i++)
{
random_ints[i] = rand();
srand(random_ints[i]);
i++;
}
}
Not at all what I thought
I found the problem with my code, and the reason I was getting about 10 pages of errors:
cout << "Number of random data values in array (0-200)? ";
cin >> num_values >> endl;
cout << "Bound on maximum value? ";
cin >> bound >> endl;
I put my endl in the stream of the cin statement.
I switched the code to look like this:
cout << "Number of random data values in array (0-200)? ";
cin >> num_values;
cout << endl; << "Bound on maximum value? ";
cin >> bound;
cout << endl;
and it compiled.