// This program should scan in a budget price and 3 grocery items and their // costs into a struct array, and determine which items are over budget. // // Unfortunately, this code contains a number of errors. // It's your job to fix them, good luck! #include #include #define SIZE 3 #define MAX_GROCERY_NAME 20 /////////////////////// DO NOT CHANGE THIS STRUCT ///////////////////////////// struct grocery_item { char item_name[MAX_GROCERY_NAME]; double cost; }; //////////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE ANY OF THE CODE BELOW HERE // // THE CODE BELOW IS SIMPLY TO ASSIST IN SCANNING IN THE GROCERY ITEMS AND // // THEIR COSTS INTO THE ARRAY. THERE ARE NO BUGS ABOVE // //////////////////////////////////////////////////////////////////////////////// int main(void) { printf("Enter a budget: "); double budget; scanf("%lf", &budget); getchar(); printf("Enter 3 grocery items and their costs:\n"); struct grocery_item array[SIZE]; for (int i = 0; i < SIZE; i++) { fgets(array[i].item_name, MAX_GROCERY_NAME, stdin); scanf("%lf", &array[i].cost); getchar(); } printf("Checking grocery items...\n"); //////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE ANY OF THE CODE ABOVE HERE // // THE CODE ABOVE IS SIMPLY TO ASSIST IN SCANNING IN THE GROCERY ITEMS AND// // THEIR COSTS INTO THE ARRAY. THERE ARE NO BUGS ABOVE // //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// ////////////////////// ONLY EDIT CODE BELOW HERE /////////////////////////// //////////////////////////////////////////////////////////////////////////// int j = 0; int over_budget = 0; while (j < SIZE) { if (array[j].cost < budget) { over_budget++; } } if (over_budget == budget) { printf("Oh no, all your items are over budget!\n"); } else if (over_budget == 0) { printf("Great work! All your items are within budget!\n"); } else { int k = 1; printf("Over budget items:\n"); while (k < SIZE) { if (array[k].cost > budget) { printf("%s", array[k].cost); } k++; } } return 0; }