Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- void browseshop(int decision , int n , string fruits[] , int size , int n1);
- int main(){
- string fruits[] = {"apple", "banana", "mango", "orange", "pineapple", "pear"};
- int size = sizeof(fruits)/sizeof(string);
- char rr;
- /* cout << size; */
- int decision;
- int n;
- int n1 = n - 1;
- cout << "welcome to the brilliant fruit palor!\n";
- do{
- browseshop(decision , n , fruits , size , n1);
- cout << "Would you like to browse our shop again?: \n";
- cin >> rr;
- }while(rr != 'n');
- cout << "Thank you for your precious time to visit our shoop!\n";
- return 0;
- }
- void browseshop(int decision , int n , string fruits[] , int size , int n1){
- cout << "what would you like to do?: \n";
- cout << "1. summon the whole list of fruits that we have on our menu? (we have " << size << " fruits as of now!\n";
- cout << "2. summon the 'n'th fruit of our menu.\n";
- cin >> decision;
- switch(decision){
- case 1: {
- for(int i = 0; i < size; i++){
- cout << fruits[i];
- cout << endl;
- }
- } break;
- case 2: {
- cout << "enter the 'n': \n" << endl;
- cin >> n;
- if(n <= size && n > 0){
- int n2 = n - 1;
- cout << "the fruit at " << n << " position is " << fruits[n2] << ". \n";
- }
- else{cout << "Enter a valid fruit number, remeber we only have " << size << " as of now!\n";}
- } break;
- default: { cout << "pick a valid operation!.\n";
- } break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment