Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void best_combination(int budget, int ff_cost, int hf_cost, int *final_ff_num, int *final_hf_num);
- int main(void) {
- //toysQuestion();
- healthfoodQuestion();
- return 0;
- }
- void healthfoodQuestion() {
- int ff_cost = 0, hf_cost = 0, budget = 0, final_ff_num = 0, final_hf_num = 0;
- printf("Enter budget: $");
- scanf("%d", &budget);
- printf("Enter fast-food cost per meal: $");
- scanf("%d", &ff_cost);
- printf("Enter health-food cost per meal: $");
- scanf("%d", &hf_cost);
- best_combination(budget, ff_cost, hf_cost, final_ff_num, final_hf_num);
- }
- void best_combination(int budget, int ff_cost, int hf_cost, int final_ff_num, int final_hf_num)
- {
- int hf_array[100], ff_array[100], ff_temp = 0,
- hf_temp = 0, ff_counter = 0, hf_counter = 0,
- total = 0;
- if (budget % (ff_cost + hf_cost) != 0)
- {
- for (int i = 0; i < budget; i++)
- {
- if (budget % (ff_cost + hf_cost) != 0) {
- if (ff_cost < hf_cost) {
- if (budget - hf_cost < hf_cost) {
- if ((budget - ff_cost) < (budget - hf_cost)) {
- final_ff_num++;
- budget -= ff_cost;
- }
- else {
- final_hf_num++;
- budget -= hf_cost;
- }
- }
- final_ff_num++;
- budget -= ff_cost;
- }
- else {
- if (budget - ff_cost < ff_cost) {
- if ((budget - hf_cost) < (budget - ff_cost)) {
- final_hf_num++;
- budget -= hf_cost;
- }
- else {
- final_ff_num++;
- budget -= ff_cost;
- }
- }
- final_hf_num++;
- budget -= hf_cost;
- }
- }
- }
- }
- else {
- for (int i = 1; hf_temp < budget; i++)
- {
- hf_array[i - 1] = hf_cost * i;
- hf_temp += hf_cost;
- hf_counter++;
- }
- for (int i = 1; ff_temp < budget; i++)
- {
- ff_array[i - 1] = ff_cost * i;
- ff_temp += ff_cost;
- ff_counter++;
- }
- for (int i = 0; i < hf_counter; i++)
- {
- for (int j = 0; j < ff_counter; j++)
- {
- total = hf_array[i] + ff_array[j];
- if (total != budget) {
- total = 0;
- }
- else {
- if (i > j)
- {
- final_hf_num = ++i;
- final_ff_num = ++j;
- }
- }
- }
- }
- }
- printf("Number of fast-food meals = %d \n", final_ff_num);
- printf("Number of health-food meals = %d \n", final_hf_num);
- printf("Remaining Budget = %d \n", budget);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement