The Issue is when first time I run my Program and enter 5 than program will return Friday and after this press y to restart the operation without closing the console and enter 9 the program will return the default error message and will also return Friday which is a bad error in my code and I cannot Identify what makes it wrong. The Code:
#include <iostream>
#include <limits>
using namespace std;
enum Dayofweek {monday = 1 , tuesday = 2, wednesday = 3, thursday = 4, friday = 5, saturday = 6, sunday = 7};
string Day (Dayofweek);
int main()
{
int i;
char resTart;
Dayofweek d = monday;
do
{
cin.clear();
system ("cls");
cout << "Enter the day of a week:[1] [2] [3] [4] [5] [6] [7]: ";
while (!(cin >> i))
{
//system ("cls");
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
system ("cls");
cout << "Invalid Input detected, Only numbers are allowed. 1, 2, 3, 4 ,5 ,6 ,7. Try Again." << '\n';
cout << "Enter the day of a week: ";
}
cout << Day (Dayofweek (i)) << '\n';
do
{
cin.clear();
cout << "Do you want to Continue [Y/n]" << '\n';
cin >> resTart;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
system ("cls");
}while (resTart != 'Y' && resTart != 'y' && resTart != 'N' && resTart != 'n' );
}while (resTart == 'Y' || resTart == 'y');
}
string Day (Dayofweek d)
{
switch (d)
{
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
case 7:
return "Sunday";
default:
cout << "Invalid Input detected, Only numbers are allowed in limit to 7 days of week, Try Again." << '\n';
}
}
OutPut in Console: Enter the day of a week:1 [2] [3] [4] [5] [6] [7]: 9 Invalid Input detected, Only numbers are allowed. 1, 2, 3, 4 ,5 ,6 ,7. Try Again. Friday Do you want to Continue [Y/n]
