aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk5
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-04-01 20:33:09 -0500
committerRossTheRoss <msattr@gmail.com>2019-04-01 20:33:09 -0500
commitf7ebdd06d01d2fdd75744bc075ecd86fe0bd9100 (patch)
tree87ec25c21b0122f4301cf990c3443733643f7507 /ee1301/wk5
parentFinish A (diff)
downloadhomework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.tar
homework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.tar.gz
homework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.tar.bz2
homework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.tar.lz
homework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.tar.xz
homework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.tar.zst
homework-f7ebdd06d01d2fdd75744bc075ecd86fe0bd9100.zip
Fix an oopsie
Diffstat (limited to 'ee1301/wk5')
-rw-r--r--ee1301/wk5/hw5_directory/strap012_HW5B.cpp25
-rw-r--r--ee1301/wk5/hw5_directory/strap012_HW5C.cpp11
2 files changed, 29 insertions, 7 deletions
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 <iostream>
+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