Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. char prod[10][100];
  7. int qty[10][2];
  8. int price[10][2];
  9. int sortQty[10];
  10. int index, maxIndex, total, maxIncome, i, j;
  11. int pid, pq;
  12.  
  13. int main()
  14. {
  15. while(true) {
  16. cout << "Introducere produs #" << index + 1 << ":";
  17. cin.get(prod[index], 100);
  18. cin.get();
  19.  
  20. if(strlen(prod[index]) == 0) {
  21. maxIndex = index;
  22. break;
  23. }
  24.  
  25. qty[index][0] = index;
  26. cout << "Introducere cantitate pentru " << prod[index] << ":";
  27. cin >> qty[index][1];
  28.  
  29. price[index][0] = index;
  30. cout << "Introducere pret pentru " << prod[index] << ":";
  31. cin >> price[index][1];
  32.  
  33. index++;
  34. cin.get();
  35. }
  36.  
  37. cout << endl << "Produse Disponibile: " << endl;
  38.  
  39. for(i = 0; i < maxIndex; i++) {
  40. cout << prod[i] << " (x" << qty[i][1] << "): " << price[i][1] << " Lei (Valoare Totala: " << qty[i][1] * price[i][1] << ")" << endl;
  41. }
  42.  
  43. // Sort by Lowest Quantities
  44. for(i = 0; i < maxIndex; i++) {
  45. for(j = 0; j < i; j++) {
  46. if(qty[i][1] < qty[j][1]) {
  47. pid = qty[i][0];
  48. pq = qty[i][1];
  49. qty[i][0] = qty[j][0];
  50. qty[i][0] = qty[j][1];
  51. qty[j][0] = pid;
  52. qty[j][1] = pq;
  53. }
  54. }
  55. }
  56.  
  57. for(i = 0; i < maxIndex; i++) {
  58. cout << qty[i][0];
  59. }
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement