I want to make a case statement based on an iterable, but I understand that the case expression must be a constant. What is a workaround for this?
I tried the below code, but it still does not work.
#include <iostream>
using std::cout;
using namespace std;
int main()
{
int i = 0;
while( i >= 0)
{
const int z = i;
cout << "Enter a number other than " << z << "!\n";
int choice;
cin >> choice;
switch(choice){
case z: cout << "Hey! you weren't supposed to enter "<< z <<"!"; return 0; break;
default: if(i==10)
{
cout << "Wow, you're more patient then I am, you win."; return 0;
}
break;
}
i++;
}
}