This is my code: { int apples = 0, oranges = 0, pears = 0, tomatoes…
Question Answered step-by-step This is my code: { int apples = 0, oranges = 0, pears = 0, tomatoes… Image transcription textPart-2 Output Example (Note: Use the YELLOW hfghlighted useH’nput data for submission] Grocery ShoppingHow many APPLES do you need? : —1 ERROR: Value must be 6 or more. How many APPLES do you need? : 16How many ORANGES do you need? : -1 ERROR: Value must be a or more. How many ORANGES … Show more… Show more This is my code:{ int apples = 0, oranges = 0, pears = 0, tomatoes = 0, cabbages = 0; int pickApples, pickOranges, pickPears, pickTomatoes, pickCabbages; double remaining; int i = 1, pickQty; while (i = 1) { printf(“Grocery Shopping” “n================”); do { printf(“nHow many APPLES do you need? : “); scanf(” %d”, &apples); if (apples < 0) printf("ERROR: Value must be 0 or more."); } while (apples < 0); do { printf("nHow many ORANGES do you need? : "); scanf(" %d", &oranges); if (oranges < 0) printf("ERROR: Value must be 0 or more."); } while (oranges < 0); do { printf("nHow many PEARS do you need? : "); scanf(" %d", &pears); if (pears < 0) printf("ERROR: Value must be 0 or more."); } while (pears < 0); do { printf("nHow many TOMATOES do you need? : "); scanf(" %d", &tomatoes); if (tomatoes < 0) printf("ERROR: Value must be 0 or more."); } while (tomatoes < 0); do { printf("nHow many CABBAGES do you need? : "); scanf(" %d", &cabbages); if (cabbages < 0) printf("ERROR: Value must be 0 or more."); } while (cabbages < 0); // Picking products section printf("n--------------------------" "nTime to pick the products!" "n--------------------------"); printf("n"); do { printf("nPick some APPLES... how many did you pick? : "); scanf(" %d", &pickApples); if (pickApples < 1) { printf("ERROR: You must pick at least 1!"); } else if (pickApples > apples) { printf(“You picked too many… only %d more APPLE(S) are needed.”, apples); } else if (pickApples < apples) { printf("Looks like we still need some APPLES..."); apples -= pickApples; } else if (pickApples = apples) { printf("Great, that's the apples done!"); apples -= pickApples; remaining = (apples % pickApples); } } while (remaining >= 1); printf(“n”); do { printf(“nPick some PEARS… how many did you pick? : “); scanf(” %d”, &pickPears); if (pickPears < 1) { printf("ERROR: You must pick at least 1!"); } else if (pickPears > pears) { printf(“You picked too many… only %d more PEAR(S) are needed.”, pears); } else if (pickPears < pears) { printf("Looks like we still need some PEARS..."); pears -= pickPears; } else if (pickPears = pears) { printf("Great, that's the pears done!"); pears -= pickPears; remaining = (pears % pickPears); } } while (remaining >= 1); printf(“n”); do { printf(“nPick some CABBAGES… how many did you pick? : “); scanf(” %d”, &pickCabbages); if (pickCabbages < 1) { printf("ERROR: You must pick at least 1!"); } else if (pickCabbages > cabbages) { printf(“You picked too many… only %d more CABBAGE(S) are needed.”, cabbages); } else if (pickCabbages < cabbages) { printf("Looks like we still need some CABBAGES..."); cabbages -= pickCabbages; } else if (pickCabbages = cabbages) { printf("Great, that's the cabbages done!"); cabbages -= pickCabbages; remaining = (cabbages % pickCabbages); } } while (remaining >= 1); printf(“nn”); printf(“All the items are picked!”); printf(“nnDo nother shopping? (0=NO): “); scanf(” %d”, &i); printf(“n”); printf(“Grocery Shopping” “n================”); printf(“n”); printf(“How many APPLES do you need? : nn”); scanf(” %d”, &apples); printf(“How many ORANGES do you need? : nn”); scanf(” %d”, &oranges); printf(“How many PEARS do you need? : nn”); scanf(” %d”, &pears); printf(“How many TOMATOES do you need? : nn”); scanf(” %d”, &tomatoes); printf(“How many CABBAGES do you need? : nn”); scanf(” %d”, &cabbages); printf(“n”); do { printf(“nPick some ORANGES… how many did you pick? : “); scanf(” %d”, &pickOranges); if (pickOranges < 1) { printf("ERROR: You must pick at least 1!"); } else if (pickOranges > oranges) { printf(“You picked too many… only %d more ORANGE(S) are needed.”, oranges); } else if (pickOranges < oranges) { printf("Looks like we still need some ORANGES..."); oranges -= pickOranges; } else if (pickOranges = oranges) { printf("Great, that's the oranges done!"); oranges -= pickOranges; remaining = (oranges % pickOranges); } } while (remaining >= 1 ); printf(“n”); do { printf(“nPick some TOMATOES… how many did you pick? : “); scanf(” %d”, &pickTomatoes); if (pickTomatoes < 1) { printf("ERROR: You must pick at least 1!"); } else if (pickTomatoes > tomatoes) { printf(“You picked too many… only %d more TOMATO(ES) are needed.”, tomatoes); } else if (pickTomatoes < tomatoes) { printf("Looks like we still need some TOMATOES..."); tomatoes -= pickTomatoes; } else if (pickTomatoes = tomatoes) { printf("Great, that's the tomatoes done!"); tomatoes -= pickTomatoes; remaining = (tomatoes % pickTomatoes); } } while (remaining >= 1); } printf(“nYour tasks are done for today – enjoy your free time!”); return 0;} I have some question:- Is the “Grocery Shopping” part repeated? If it is, why does the system doesn’t show “Error” message when I input “0” in the second round of shopping?- How does the compiler know to stop after picking up 3 fruits? (Apples, Pears, Cabbages) -> this one I think I should use the % modulus, but I don’t really know how to set it up.- At the second round of shopping, how to avoid repeating questioning about Apple, Pears, Cabbages since they are done from the first round?- When I use Do-While for the whole thing, how to set up to quit the loop without using “break”/”done”…..? I tried to use int i, and set it at the end }while (i == 1), but it doesn’t work. Please help. Thank you so much. Computer Science Engineering & Technology Software engineering IPC 144 Share QuestionEmailCopy link Comments (0)


