From f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 1 Apr 2019 20:33:09 -0500 Subject: Fix an oopsie --- ee1301/wk5/hw5_directory/strap012_HW5B.cpp | 25 ++++++++++++++++++------- ee1301/wk5/hw5_directory/strap012_HW5C.cpp | 11 +++++++++++ testData.txt | 3 +++ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 ee1301/wk5/hw5_directory/strap012_HW5C.cpp create mode 100644 testData.txt diff --git a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp index 4576e59..ca6d150 100644 --- a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp +++ b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp @@ -8,23 +8,34 @@ int main(int argc, char *argv[]) cout << "Invalid input!" << endl << " USAGE: ./rand-array m n max" << endl; return 2; } + srand(time(NULL)); int m, n, max; m = atoi(argv[1]); //number of rows n = atoi(argv[2]); //number of columns int randArray[m][n]; - max = atoi(argv[3]); //Maximum number + max = atoi(argv[3]); //Maximum number in array + + //Loop to make the random array for (int curRow = 0; curRow < m; curRow++) { for (int curCol = 0; curCol < n; curCol++) - { - if (rand() % 2 == 1) { - randArray[curRow][curCol] = -1 * (rand() % max); + { + if (rand() % 2 + 1 == 2) { //Decide the sign of the number + randArray[curRow][curCol] = -1 * (rand() % (max+1)); } else { - randArray[curRow][curCol] = (rand() % max); + randArray[curRow][curCol] = (rand() % (max+1)); } } } - - cout << endl; + + //Loop to output the array in the console + for (int curRow = 0; curRow < m; curRow++) + { + for (int curCol = 0; curCol < n; curCol++) + { + cout << randArray[curRow][curCol] << " "; + } + cout << endl; + } } \ No newline at end of file diff --git a/ee1301/wk5/hw5_directory/strap012_HW5C.cpp b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp new file mode 100644 index 0000000..9948820 --- /dev/null +++ b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main(int argc, char *argv[]) +{ + // if (argc != 4) { + // cout << "Invalid input!" << endl << " USAGE: ./rand-array m n max" << endl; + // return 2; + // } + +} \ No newline at end of file diff --git a/testData.txt b/testData.txt new file mode 100644 index 0000000..f067f0b --- /dev/null +++ b/testData.txt @@ -0,0 +1,3 @@ +-14 58 22 -4 +-63 -24 -5 -4 +-12 48 -39 -82 -- cgit v1.2.3