I need to write a program that will ask for a # associated with a day of the week. once they select I need a a Y/N to continue with another try or exit the program. I'm just stuck. I'm sure the do loop with the extra while loop is not needed but I can not get this to work. Any help would be great. I feel I'm close and just need a nudge in the right direction.
#include <iostream>
usingnamespace std;
int main()
{
constchar *days[7] = {"Sunday", "Moday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
int numb, choice;
do
{
cout << "Enter a number for a day of the week (Sun = 1, Sat = 7): ";
cin >> numb;
while (numb < 1 || numb > 7)
{
cout << numb << " is invalid\n";
cout << "Enter a number for a day of the week (Sun = 1, Sat = 7): ";
cin >> numb;
}
cout << days[numb - 1] << '\n';
cout << "Do you wish to continue? ";
cin >> choice;
while (choice == 'y' || choice == 'n')
{
cout << "Do you wish to continue? ";
cin >> choice;
}
}
while (choice == 'y');
cout << "Goodbye! Thank you for using our program!\n";
return 0;
}
Thank you for the quick response. Hopefully soon my code will start looking that neat and
that compact! There is still the issue with if the user selects "y" (after asking "do you wish to continue") it needs loops back around and start over. only "n" should exit out and give "Goodbye" message. This still ends the program no matter what is chosen.