### Do-While Loop Error

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include #include 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.