Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NUM 100
- int const fee = 0;
- int const fun = 1;
- // the sorting function the function takes the array party and its size to arrange the parties and their fees descendingly according to fun per fee
- void partySort(int party[][2], int size) {
- int insert[2];
- for (int next = 1; next < size; ++next)
- {
- insert[0] = party[next][fee];
- insert[1] = party[next][fun];
- int moveItem = next;
- while (moveItem > 0 && static_cast<double>(party[moveItem - 1][fun]) / party[moveItem - 1][fee] <static_cast<double>(insert[1]) / insert[0])
- {
- party[moveItem][fee] = party[moveItem - 1][fee];
- party[moveItem][fun] = party[moveItem - 1][fun];
- moveItem--;
- }
- party[moveItem][fee] = insert[0];
- party[moveItem][fun] = insert[1];
- }
- }
- void main() {
- // welcome statement
- cout << " *** Welcome to Party Hard... Pay A Lot less *** " << endl << endl << endl;
- // decalring and initializing variables
- int number, budget, sum = 0, funsum = 0;
- int party[NUM][2];
- //Inputing the data of parties with user validation process
- cout << "Please, enter the number of parties: ";
- cin >> number;
- cout << endl << "Please, enter budget (0 ~ 500): ";
- cin >> budget;
- cout << endl;
- for (; budget > 500;)
- {
- cout << "The budget is too much\n" << "please enter the budget again: "; //user validation for budget between 0 and 500
- cin >> budget;
- }
- //Enter the price for each party
- for (int i = 0; i<number; i++)
- {
- cout << "please enter party " << i + 1 << " fee : ";
- cin >> party[i][fee];
- cout << endl;
- for (; (party[i][fee]>25) || (party[i][fee] <5);) //user validation for fee of the party between 5 and 25
- {
- cout << "The Party's fee is too high\n" << endl << "please enter the fee again of party(5 ~ 25) " << i+1 <<" : ";
- cin >> party[i][fee];
- cout << endl;
- }
- //Enter the fun for each party
- cout << "please enter party " << i + 1 << " fun (0 ~ 10): ";
- cin >> party[i][fun];
- for (; (party[i][fun]<0) || (party[i][fun]>10);) //user validation for fun of the party between 0 and 10
- {
- cout << "The Party's fun is not in range\n" << endl << "please enter the fun of the party of party " << i + 1 << " (0 ~ 10) : ";
- cin >> party[i][fee];
- cout << endl;
- }
- cout << endl;
- }
- partySort(party, number); //Calling the sorting function
- //Outputting the result
- cout << endl << endl << endl << endl << endl << endl << endl << " Order of parties by fun per fee " << endl << endl << endl;
- cout << "Party no." << " " << "** Fee :'( **" << " " << "** Fun :D **" << endl << endl;
- for (int i = 0; i < number; i++)
- {
- cout << i + 1 << " " << party[i][fee] << " " << party[i][fun] << endl << endl;
- }
- cout << endl << endl << endl << endl << endl << endl << endl << " Our Program Suggests these Parties to get most fun :-) " << endl << endl << endl;
- for (int i = 0; i < budget; i++)
- {
- cout << i + 1 << " " << party[i][fee] << " " << party[i][fun] << endl << endl;
- cout << endl << endl << endl << " And Dont forget to party HARD :D (o_0) " << endl << endl << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement