There is a few lines of my code that I would like to define as a function because I plan to use it multiple times. portion of code is as follows:
// loop within loop used to reorder with highest price at the top
for(i=0;i<x;i++){
    for(t=i;t<x;t++){
        if(f[i].price < f[t].price) {
            temp = f[i].price;
            f[i].price = f[t].price;
            f[t].price = temp;
        }
    }
}
I hope to be able to enter new values for x and f each time I call the function. I have included all of my code below. If I'm unclear about my objective in anyway please feel free to ask. I apologize in advance for the improper terminology I am new to this. Thank you
#include <iostream>
using namespace std;
struct List
    {
        char name[10];
        int price;
        };
int main()
{
    //x represents number of structures within array!
     int x; 
    cout << "How many items would you like to list under the fruit menu?\n";
    cin >> x;
    //array of structures fruit
    struct List f[x];
    int i;
    //input values into structure
    for (i = 0; i < x; i++) {
      cout << "\nEnter fruit name, and price.\n";
      cin >> f[i].name;
      cin >> f[i].price;
    };
    //variables for reordering
     int temp;
     int t;
    // loop within loop used to reorder with highest price at the top
    for(i=0;i<x;i++){
        for(t=i;t<x;t++){
            if(f[i].price < f[t].price) {
                temp = f[i].price;
                f[i].price = f[t].price;
                f[t].price = temp;
            }
        }
    }
    //Output of menus
    //fruit Menu
    cout << "\n\nFruit Menu";
     for (i = 0; i < x; i++) {
        cout << "\n" << f[i].name << " $" << f[i]. price;
        };
    return 0;
}

std::sort()would be much better - Bubble Sort is almost never a good idea!