Hello,
I'm just starting with C++, and I'm making a couple really simple programs. I have two questions about the one I'm on right now. They are:
1. Is there a function that will stop the script from running like exit(); or something? For example, if I only wanted the script to run if a user entered a number between 0 and 6 and they entered 20, I'd want the script to return a message saying "That was an invalid number. Please try again!" and stop from going on. How would I do this?
2. How do you get the actual value of something in an enum and print it? I made an enum called Days, and it has the name of the days from Sunday to Monday. Then the program asks the user to put in a number. How can I match that number with the value of the thing in the enum and print out the name of the day? Lol, for example:
Now how would I print out the day that the number they put in represents in the enum?Code:#include <iostream>
int main() {
enum Days {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
int x, DayOff;
cout <<"What day would you like off (0-6)? ";
cin >> x;
DayOff = Days(x);
}
Thanks,
CougarElite
