Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- char prod[10][100];
- int qty[10][2];
- int price[10][2];
- int sortQty[10];
- int index = 1, maxIndex, total, i, j;
- int maxIncome, roundMode = -1;
- int pid, pq;
- int main()
- {
- while(true) {
- cout << "Introducere produs #" << index << ":";
- cin.get(prod[index], 100);
- cin.get();
- if(strlen(prod[index]) == 0) {
- break;
- }
- qty[index][0] = index;
- cout << "Introducere cantitate pentru " << prod[index] << ":";
- cin >> qty[index][1];
- price[index][0] = index;
- cout << "Introducere pret pentru " << prod[index] << ":";
- cin >> price[index][1];
- index++;
- maxIndex = index;
- cin.get();
- }
- cout << endl << "Produse Disponibile: " << endl;
- for(i = 1; i < maxIndex; i++) {
- cout << i << ". " << prod[i] << " (x" << qty[i][1] << "): " << price[i][1] << " Lei (Valoare Totala: " << qty[i][1] * price[i][1] << ")" << endl;
- }
- // Sort by Lowest Quantities
- for(i = 1; i < maxIndex; i++) {
- for(j = 1; j < i; j++) {
- if(qty[i][1] < qty[j][1]) {
- pid = qty[i][0];
- pq = qty[i][1];
- qty[i][0] = qty[j][0];
- qty[i][1] = qty[j][1];
- qty[j][0] = pid;
- qty[j][1] = pq;
- }
- }
- }
- /* Show sorted quantities
- for(i = 1; i < maxIndex; i++) {
- cout << qty[i][0] << " " << qty[i][1] << endl;
- } */
- cout << endl << "Profit maxim dupa vanzarea a 50% din stocul ultimelor 3 produse dupa cantitate: " << endl;
- for(i = 1; i <= 3; i++) {
- if(qty[i][1] % 2 != 0) {
- qty[i][1] = qty[i][1] + roundMode;
- }
- cout << prod[qty[i][0]] << " (x" << qty[i][1] << "): " << price[qty[i][0]][1] << " Lei (Valoare Totala: " << price[qty[i][0]][1] * qty[i][1] << ")" << endl;
- total += price[qty[i][0]][1] * qty[i][1];
- }
- cout << "=> Total maxim dupa criteriul specificat: " << total << " Lei";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement