What did i do wrong on this code? 81.2 practice c++
so this is the practice question, ive been stuck on it for a little and have been playing around. This code seems to work best, i get 4 of the 5 Test cases correct. the problem is that the case that is wrong is hidden so i can't see what they inputted to help me fix the code for that situation. You are making a digital menu, which takes a number as user input, and outputs the corresponding menu item. However, the users can input anything, even numbers that are not present in the menu. Handle wrong user input, by throwing an exception with code 4040 and outputting "404 - not found", if it is out of range of the given menu. Note that the menu is given as an array so you need to output the input index, if it exist. #include <iostream> using namespace std; int main() { string menu[] = {"fruits", "chicken", "fish", "cake"}; try { int x; cin >> x; //your code goes here if(x>0 && x<=3){ cout << menu[x] << endl; } else{ throw(x); } } catch(int num){ //and here cout<<"404 - not found"; } }