This is what I completed. It does the job. Do you think it could be simplified in any way??
Code:
#include <stdio.h>
int main(void) {
// Variables are declared
int subway_cost, lazy_cost, difference;
int card_balance, final_balance, total_cost;
int subway_meals, lazy_meals, total_meals;
// User inputs the values
printf("How much does a meal at Subway cost?\n");
scanf("%d", &subway_cost);
printf("How much does a meal at Lazy Moon cost?\n");
scanf("%d", &lazy_cost);
printf("How many meals will you eat this semester?\n");
scanf("%d", &total_meals);
printf("How much money did your parents put on your meal card?\n");
scanf("%d", &card_balance);
// Price difference of the meals
difference = abs(lazy_cost-subway_cost);
// Total meals are divided between both restaurants as integers
subway_meals = total_meals/2;
lazy_meals = total_meals-subway_meals;
// Total cost of the divided number of meals is calculated
total_cost = (subway_meals*subway_cost)+(lazy_meals*lazy_cost);
// Loop adjusts number of meals until total cost is <= card balance
while (total_cost > card_balance) {
subway_meals++;
lazy_meals--;
total_cost = (subway_meals*subway_cost)+(lazy_meals*lazy_cost); }
// Final balance calculated to determine if meal upgrade is available
final_balance = card_balance-total_cost;
// Loop adjusts number of meals if upgrade is available
while (final_balance >= difference) {
subway_meals--;
lazy_meals++;
final_balance = card_balance-((subway_meals*subway_cost)+(lazy_meals*lazy_cost)); }
// Number of meals to be eaten at each place is displayed
printf("You will eat %d meals at Subway and %d meals at Lazy Moon.\n", subway_meals, lazy_meals);
// If statement chooses output based on final balance value
if (final_balance > 0)
printf("You will have $%d left on your card.\n", final_balance);
else
printf("You will have no balance left on your card.\n");
system("pause");
return 0;
}