Do-While Loop Error

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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int DAY1, QDAYS, DAYNUM, COL;
    
    //Intro
    cout << "ONE MONTH CALENDAR" << endl;
    cout << "===================\n" << endl;
    cout << "Written by Randolph Gibson" << endl;
    cout << "Coded by Robert Hirsch\n" << endl;
    cout << "Select from the menu below the numeral indicating which day of the week\nshould appear as the first day of the month on your calendar.\n" << endl;
    cout << "FIRST DAY OF MONTH MENU\n" << endl;
    cout << "1. Sunday\n2. Monday\n3. Tuesday\n4. Wednesday\n5. Thursday\n6. Friday\n7. Saturday\n" << endl;
    
    //Do-while loop
    do
    {
               cout << "Numeral (1-7)\n- ";
               cin >> DAY1;
               
               
              } while ((DAY1 < 1) && (DAY1 > 7));
               


                     
    

    
    //Second Do-while LOOP
    
    do
    {
             cout << "How many days are in the month? (28-31)\n- ";
             cin >> QDAYS;
             
            } while (QDAYS < 28 && QDAYS > 31);
             
             

    system ("CLS");               
    cout << "+---------+---------+---------+---------+---------+---------+---------+" << endl;
    cout << "|   SUN   |   MON   |   TUE   |   WED   |   THU   |   FRI   |   SAT   |" << endl;
    cout << "+---------+---------+---------+---------+---------+---------+---------+" << endl;
    
    system("pause");
    return 0;
}




I've started this Calendar Program, however when you enter invalid numbers such as 231 or 32 it does not loop and continues the program.
Last edited on
pieman125 wrote:
while ((DAY1 < 1) && (DAY1 > 7));
Can it be both below 1 AND above 7? This loop will only run once because the condition can never be true.
Last edited on
Line 26: while ((DAY1 < 1) && (DAY1 > 7))
A number can't be less than 1 and greater than 7 at the same time. Use logical or instead of logical and: ||
Same goes for line 41.
Last edited on
Topic archived. No new replies allowed.