In: Computer Science
Restaurant Selector
You have a group of friends coming to visit for your high school reunion, and you want to take them out to eat at a local restaurant. You aren’t sure if any of them have dietary restrictions, but your restaurant choices are as follows:
Joe’s Gourmet Burgers –
Vegetarian: No,
Vegan: No,
Gluten-Free: No
Main Street Pizza Company –
Vegetarian: Yes,
Vegan: No,
Gluten-Free: Yes
Corner Café –
Vegetarian: Yes,
Vegan: Yes,
Gluten-Free: Yes
Mama’s Fine Italian –
Vegetarian: Yes,
Vegan: No,
Gluten-Free: No
The Chef’s Kitchen –
Vegetarian: Yes,
Vegan: Yes,
Gluten-Free: Yes
Write a program that asks whether any members of your party are vegetarian, vegan, or gluten-free, and then display only the restaurants that you may take the group to. Here is an example of the program’s output:
Is anyone in your party a vegetarian? yes[Enter] Is anyone in your party a vegan? no[Enter] Is anyone in your party gluten-free? yes[Enter] Here are your restaurant choices: Main Street Pizza Company Corner Cafe The Chef’s Kitchen
Here is another example of the program’s output:
Is anyone in your party a vegetarian? yes [Enter] Is anyone in your party a vegan? yes [Enter] Is anyone in your party gluten-free? yes [Enter] Here are your restaurant choices: Corner Cafe The Chef’s Kitchen
As you not asked for any specific languge, I am answering in C++.
By the way, code is easy to undersatand, so you can have a idea and covert it in your own desired language.
Assumption: I am assuming, if there is a vegan guy in group then, you will say yes for both vegan and vegetarian.
Approch :
First I asked user to tell me what is your requirement(took input from console).
I used conditional statements(if-else) to consider all possible cases.
All restaurant that satisfies group's requirement, I printed them.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string vegetarian, vegan, GlutenFree;
cout<<"Is anyone in your party a vegetarian? ";
cin>>vegetarian;
cout<<"\nIs anyone in your party a vegan? ";
cin>>vegan;
cout<<"\nIs anyone in your party gluten-free? ";
cin>>GlutenFree;
if((vegetarian == "no") && (vegan == "no") && (GlutenFree == "no"))
cout<<"Joe’s Gourmet Burgers\nMain Street Pizza Company\nCorner Café\nMama’s Fine Italian\nThe Chef’s Kitchen\n";
else if((vegetarian == "yes") && (vegan == "no") && (GlutenFree == "no"))
cout<<"Main Street Pizza Company\nCorner Café\nMama’s Fine Italian\nThe Chef’s Kitchen\n";
else if((vegetarian == "yes") && (vegan == "no") && (GlutenFree == "yes"))
cout<<"Main Street Pizza Company\nCorner Café\nThe Chef’s Kitchen\n";
else if((vegan == "yes") && (GlutenFree == "no"))
cout<<"Corner Café\nThe Chef’s Kitchen\n";
else if((vegan == "yes") && (GlutenFree == "yes"))
cout<<"Corner Café\nThe Chef’s Kitchen\n";
}
Output :
testcase 1:
testcase 2 :
Try running above code on your own system.
Like, if this helped :)