Guest User

Untitled

a guest
Oct 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. void chefsMenuitems();
  4.  
  5. void chefsMenuitems(int P[], int arr_size) {
  6. int count = 0;
  7. int current_item = 0;
  8. int n = 0;
  9. int i = 0;
  10. for (int j = 0; j < arr_size; j++ ) {
  11.  
  12. while(P[j] > 0) {
  13.  
  14.  
  15. for ( i = 0; current_item < P[j]; i++) {
  16.  
  17. current_item = pow(2,(i));
  18.  
  19. if (current_item > P[j]){
  20.  
  21. current_item = pow(2,(i - 1));
  22. break;
  23. }
  24. }
  25.  
  26. P[j] = P[j] - current_item;
  27. current_item = 0;
  28. n++;
  29. }
  30. count++;
  31. std::cout << "The number of menu items for price " << count << " are: " << n << "n";
  32. n = 0;
  33. current_item = 0;
  34. }
  35. }
  36.  
  37.  
  38.  
  39. int main() {
  40. int T = 0;
  41. int P[] = {0};
  42. int arr_size;
  43.  
  44. std::cout << "Please enter the number of test cases: n";
  45. std::cin >> T;
  46.  
  47. while(T < 1 || T > 5 ) {
  48.  
  49. std::cout << "Test cases must be between 1 & 5 inclusive: n";
  50. std::cin >> T;
  51.  
  52. }
  53.  
  54. arr_size = T;
  55.  
  56. for (int i = 0; i < T; i++) {
  57. std::cout << "Please enter the amount you are willing to spend: n";
  58. std::cin >> P[i];
  59.  
  60. while(P[i] < 1 || P[i] > pow(10, 5)) {
  61. std::cout << "The amount you are willing to spend must be between 1 and 10^5 inclusive: n";
  62. std::cin >> P[i];
  63. }
  64. }
  65.  
  66. chefsMenuitems(P, arr_size);
  67.  
  68. return 0;
  69. }
Add Comment
Please, Sign In to add comment