Question: Add these three functions to this code in C++ A function that displays the current value of the vector ( ttYour favorite category is item
Add these three functions to this code in C++
- A function that displays the current value of the vector (" \t\tYour favorite category is item") and returns nothing
- A function that takes in and validates user input for the vector and returns a string
- The vector should not be built in the function
- A function that takes in and validates user input to determine if we continue or not and returns a bool
Code:
#include
#include
using namespace std;
int main()
{
string choice;
string category2;
string favourite2;
//Vectors declaration
vector
vector
//Do-while loop, if anything other than y is entered, loop will stop
do{
//Ask for user input
cout<<"Please enter a category: ";
cin>>category2;
//Saving data in category vector.
category.push_back(category2);
cout<<"Please enter your favourite thing of that category: ";
cin>>favourite2;
//Saving data in favourite vector.
favourite.push_back(favourite2);
cout< cout<<"Do you have more favourites ?(y/n) "; cin>>choice; }while(choice=="Y"||choice=="y"); cout< //Print favourite vector by using for loop for (auto& it : favourite) { cout <<"Your favourite is "<< it << endl; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
