blob: d6bc9aa742d955987e5277cf0744e73ba57408aa (
plain) (
blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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/>.
*/
|