diff options
author | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
commit | 9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch) | |
tree | eb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/DoWhileLoopPractice | |
download | school-code-master.tar.gz school-code-master.tar.bz2 school-code-master.zip |
Diffstat (limited to 'C++/DoWhileLoopPractice')
-rw-r--r-- | C++/DoWhileLoopPractice/DoWhileLoopPractice.cpp | 67 | ||||
-rw-r--r-- | C++/DoWhileLoopPractice/NestedLoop-TriangleDrawing/NestedLoop-TriangleDrawing.cpp | 36 |
2 files changed, 103 insertions, 0 deletions
diff --git a/C++/DoWhileLoopPractice/DoWhileLoopPractice.cpp b/C++/DoWhileLoopPractice/DoWhileLoopPractice.cpp new file mode 100644 index 0000000..d6bc9aa --- /dev/null +++ b/C++/DoWhileLoopPractice/DoWhileLoopPractice.cpp @@ -0,0 +1,67 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include <iostream> +#include <string> +#include <iomanip> +using namespace std; + +// Named constants + +int main() { + + //Variable declaration + int i; + int score; + int choice; + + // Example 1 + cout << "Do While Loop Example 1" << endl; + + i = 11; + + do { + cout << i << " " << endl; + i = i + 5; + } while( i <= 30 ); + + cout << "Out of the Loop!" << endl << endl; + + //Example 2 + + cout << "Do While Loop Example 2" << endl; + + do { + cout << "Enter a score between 0 and 50" << endl; + cin >> score; + cout << endl; + + if(score < 0 || score > 50) { + cout << "It is an invalid input" << endl; + } + } while (score < 0 || score > 50); + cout << "That was a valid input" << endl; + + cout << "Do While Loop Example 3" << endl; + + cout << "Menu Options" << endl << endl; + cout << "1 - Option 1" << endl; + cout << "2 - Option 2" << endl; + cout << "3 - Option 3" << endl; + + do { + cout << "Enter your choice:" << endl; + cin >> choice; + } while(choice<1||choice>3); + cout << "Your choice is: " << choice << endl; +} + +/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + diff --git a/C++/DoWhileLoopPractice/NestedLoop-TriangleDrawing/NestedLoop-TriangleDrawing.cpp b/C++/DoWhileLoopPractice/NestedLoop-TriangleDrawing/NestedLoop-TriangleDrawing.cpp new file mode 100644 index 0000000..70f43ce --- /dev/null +++ b/C++/DoWhileLoopPractice/NestedLoop-TriangleDrawing/NestedLoop-TriangleDrawing.cpp @@ -0,0 +1,36 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include <iostream> +#include <string> +#include <iomanip> +using namespace std; + +// Named constants + +int main() { + + //Variable declaration + + int i, j; + cout << "Nested loop practice - drawing triangles"; + + for (i = 1; i <= 5; i++) { + + for (j = i ; j <=i ; j++) + cout << "*"; + cout << endl; + } + + +} + + /*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + |