I use Visual Studio Community 2017 for C++ Programming. I have the following code. Here, the do while loop runs several times and doesn't stop for asking input where it is supposed to. But, in the last switch case program, if I enter 1 instead of n, the program works great. PLEASE HELP!!!
// Welcome2018.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<bitset>
using namespace std;
int main()
{
string month[] = { "January", "February", "March", "April", "May", "June", "July", "August" "September", "October", "November", "December" };
int m, d, answer;
cout << "Welcome 2018!!!" << endl;
do
{
cout << "Enter the number corresponding to the month you want displayed" << endl;
cin >> m;
switch (m)
{
case 1:
cout << month[0] << endl;
cout << "Enter the date to know the day it is/will be" << endl;
cin >> d;
if (d == 7 || d == 14 || d == 21 || d == 28)
{
cout << "The day on " << d << " January is Sunday!" << endl;
}
else if (d == 1 || d == 8 || d == 15 || d == 22 || d == 29)
{
cout << "The day on " << d << " January is Monday!" << endl;
}
else if (d == 2 || d == 9 || d == 16 || d == 23 || d == 30)
{
cout << "The day on " << d << " January is Tuesday!" << endl;
}
else if (d == 3 || d == 10 || d == 17 || d == 24 || d == 31)
{
cout << "The day on " << d << " January is Wednesday!" << endl;
}
else if (d == 4 || d == 11 || d == 18 || d == 25)
{
cout << "The day on " << d << " January is Thursday!" << endl;
}
else if (d == 5 || d == 12 || d == 19 || d == 26)
{
cout << "The day on " << d << " January is Friday!" << endl;
}
else if (d == 6 || d == 13 || d == 20 || d == 27)
{
cout << "The day on " << d << " January is Saturday!" << endl;
}
}
cout << "Are you sure you want to quit?" << endl;
cout << "Enter Y/N based on your choice:";
cin >> answer;
switch (answer)
{
case 1:
answer = 1;
case 'n':
answer = 1;
default:
answer = 2;
}
} while (answer = 1);
cout << "Thank You and Come Again!!!" << endl;
return 0;
}