Guest User

#1 fruit palor in town

a guest
Jun 1st, 2026
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. void browseshop(int decision , int n , string fruits[] , int size , int n1);
  5.  
  6.  
  7. int main(){
  8.    
  9.     string fruits[] = {"apple", "banana", "mango", "orange", "pineapple", "pear"};
  10.     int size = sizeof(fruits)/sizeof(string);
  11.     char rr;
  12.    
  13.    
  14.   /*  cout << size; */
  15.    
  16.     int decision;
  17.     int n;
  18.     int n1 = n - 1;
  19.     cout << "welcome to the brilliant fruit palor!\n";
  20.    
  21.  
  22. do{
  23.  
  24.     browseshop(decision , n , fruits , size , n1);
  25.    
  26.     cout << "Would you like to browse our shop again?: \n";
  27.     cin >> rr;
  28.    
  29. }while(rr != 'n');
  30.  
  31.     cout << "Thank you for your precious time to visit our shoop!\n";
  32.    
  33.     return 0;
  34.    
  35. }
  36.  
  37. void browseshop(int decision , int n , string fruits[] , int size , int n1){
  38.    
  39.     cout << "what would you like to do?: \n";
  40.     cout << "1. summon the whole list of fruits that we have on our menu? (we have " << size << " fruits as of now!\n";
  41.     cout << "2. summon the 'n'th fruit of our menu.\n";
  42.     cin >> decision;
  43.    
  44.     switch(decision){
  45.        
  46.         case 1: {
  47.            for(int i = 0; i < size; i++){
  48.              
  49.              cout << fruits[i];
  50.              cout << endl;
  51.              
  52.            }
  53.            } break;
  54.            
  55.            
  56.         case 2:   {
  57.            
  58.            cout << "enter the 'n': \n" << endl;
  59.            cin >> n;
  60.            
  61.                 if(n <= size && n > 0){
  62.                     int n2 = n - 1;
  63.                cout << "the fruit at " << n << " position is " << fruits[n2] << ". \n";
  64.               }
  65.                 else{cout << "Enter a valid fruit number, remeber we only have " << size << " as of now!\n";}
  66.          
  67.         }  break;
  68.        
  69.        
  70.        
  71.         default: { cout << "pick a valid operation!.\n";
  72.         } break;    
  73.      
  74.     }
  75.  
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment