Write a program in C++ that creates an enumerator Fruit. Presents the list of fruits to the user and
displays the fruit name according to the number provided by the user.
#include <bits/stdc++.h>
using namespace std;
// Defining enumerator Fruit
enum Fruit{
Mango,Banana,Grapes,WaterMelon,Guavas,Avocado,Strawberry,Tomato,
};
Fruit EnumOfIndex(int i)
{
return static_cast<Fruit>(i);
}
// Driver Code
int main()
{
int x;
cout<<"Mango Banana Grapes WaterMelon Guavas Avocado Strawberry Tomato"<<endl;
cout<<"Enter a number: "<<endl;
cin>>x;
switch(x)
{
case 1:
cout<<"Mango"<<endl;
break;
case 2:
cout<<"Banana"<<endl;
break;
case 3:
cout<<"Grapes"<<endl;
break;
case 4:
cout<<"WaterMelon"<<endl;
break;
case 5:
cout<<"Guavas"<<endl;
break;
case 6:
cout<<"Avocado"<<endl;
break;
case 7:
cout<<"Strawberry"<<endl;
break;
case 8:
cout<<"Tomato"<<endl;
break;
}
return 0;
}
Comments
Leave a comment