Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- // Fill an array with fruit or vegetable
- // words, depending on user input.
- int main()
- {
- vector<string> basket; // List of foods.
- string choice; // User input.
- cout << "Do you want a basket of fruit or vegetables?\n";
- cin >> choice; // Get the user's choice.
- // If the user didn't choice fruit or vegetables.
- if ( (choice.compare("fruit") != 0) && (choice.compare("vegetables") != 0) )
- {
- // Inform the user their choice isn't available.
- cout << "I'm sorry, we don't have " << choice << ".\n";
- }
- else // Otherwise, if the user chose fruit or vegetables,
- {
- // If the user chose fruit,
- if (choice.compare("fruit") == 0)
- {
- // Add fruit words to the list.
- basket.push_back("apple");
- basket.push_back("orange");
- basket.push_back("banana");
- basket.push_back("plum");
- }
- // Otherwise, if the user chose vegetables,
- else if (choice.compare("vegetables") == 0)
- {
- // Add vegetable words to the list.
- basket.push_back("spinach");
- basket.push_back("carrots");
- basket.push_back("cauliflower");
- basket.push_back("broccoli");
- }
- cout << "Here's your basket:\n";
- // Display the basket.
- for (string food : basket) // For each item,
- {
- cout << food << '\n'; // Display it.
- }
- cout << "\nHave a nice day!\n";
- }
- // End the program.
- return 0;
- }
Add Comment
Please, Sign In to add comment