aboutsummaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-02 11:36:08 -0800
committerConnor McDowell <[email protected]>2024-02-02 11:36:08 -0800
commit567be58fb254052277f5738c599fc254ea8ccab1 (patch)
treeb4f21c859032da10025794b9f8016b04ba0b0f1c /project
parentframework set up for all files (diff)
downloadin-class-exercise-8-connormcdowell275-567be58fb254052277f5738c599fc254ea8ccab1.tar.xz
in-class-exercise-8-connormcdowell275-567be58fb254052277f5738c599fc254ea8ccab1.zip
nested loop created
Diffstat (limited to 'project')
-rw-r--r--project/NestedLoops.cpp54
-rw-r--r--project/NestedLoops.h6
-rw-r--r--project/program.cpp12
3 files changed, 67 insertions, 5 deletions
diff --git a/project/NestedLoops.cpp b/project/NestedLoops.cpp
index e451ce2..fdb59e2 100644
--- a/project/NestedLoops.cpp
+++ b/project/NestedLoops.cpp
@@ -1,3 +1,55 @@
#include "NestedLoops.h"
-#include <iostream> \ No newline at end of file
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+void NestedForLoop(size_t n, size_t m)
+{
+ for (int i = 0; i < n; ++i)
+ {
+ for (int j = 0; j < m; ++j)
+ {
+ cout << "i = " << i << ", j = " << j << endl;
+ cout << i * j << endl;
+
+ }
+ }
+}
+
+
+void NestedWhileLoop(size_t n, size_t m)
+{
+ n = 0;
+ while (n < 4)
+ {
+ m = 0;
+ while (m < 3)
+ {
+ cout << "n = " << n << ", m = " << m << endl;
+ m++;
+ }
+ cout << endl;
+ n++;
+ }
+}
+
+
+void NestedDoWhileLoop(size_t n, size_t m)
+{
+ n = 1;
+ do
+ {
+ m = 1;
+ do
+ {
+ cout << n * m << " ";
+ ++m;
+
+ } while (m <= 3);
+ cout << endl;
+ n++;
+ } while (n <=3 );
+}
diff --git a/project/NestedLoops.h b/project/NestedLoops.h
index d14b549..2f467d0 100644
--- a/project/NestedLoops.h
+++ b/project/NestedLoops.h
@@ -1,11 +1,11 @@
#ifndef NestedLoops
#define NestedLoops
-void ForLoop(size_t n);
+void NestedForLoop(size_t n, size_t m);
-void WhileLoop(size_t n);
+void NestedWhileLoop(size_t n, size_t m);
-void DoWhileLoop(size_t n);
+void NestedDoWhileLoop(size_t n, size_t m);
#endif NestedLoops
diff --git a/project/program.cpp b/project/program.cpp
index 982e803..fd7c5cf 100644
--- a/project/program.cpp
+++ b/project/program.cpp
@@ -6,10 +6,20 @@
#include <iostream>
#include "NestedLoops.h"
+using std::cout;
+using std::cin;
+using std::endl;
+
+
+
int main()
{
+ int n = 2;
+ int m = 3;
-
+ //NestedForLoop(n, m);
+ //NestedWhileLoop(n, m);
+ NestedDoWhileLoop(n, m);
return 0;
} \ No newline at end of file