This is what I am trying to accomplish
C++ HW - Files and Arrays
Create two 10-element arrays (1 is empty for now 1 is what the next line is)
Using a random number generator, fill one array with integers having a value between 1 and 100.
Print the contents of the array
Open a file for writing
Write the contents of the array to the file (the 1st rand array)
Open your file for reading (with the 1st rand array written to it)
As you read the file, write the double of each number to your second array (so basically 2x what the random numbers generated)
Print the contents of the array
I don't know how to get the 10 element array I generated with random to double.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <ctime>
#include <fstream>
using namespace std;
int main()
{
ofstream outputFile;
ifstream inputFile;
int Arrayinloop, array1, arrayout;
srand(time(NULL));
const unsigned int arrsize = 10;
int numberArray[arrsize];
int array2[arrsize];
for (int i = 0; i < arrsize; i++)
{
numberArray[i] = rand() % 100;
cin >> numberArray[i] >> Arrayinloop;
array1 += Arrayinloop;
cout << numberArray[i] << "\t";
}
outputFile.open("ArrayOut.txt");
outputFile << Arrayinloop << "\t" << endl;
outputFile.close();
cout << "Array 1 written to ArrayOut.txt\n";
inputFile.open("ArrayOut.txt");
while (inputFile >> arrayout)
{
while (cout << arrayout << endl)
{
// I want to have the double of the first array printed here
}
}
cin.get();
return 0;
}
|