Question: This program does compile. It is supposed to ask the user the choice of grades of pet foods and return the price. The user may
This program does compile. It is supposed to ask the user the choice of grades of pet foods and return the price. The user may answer in uppercase or lower. So answers may be 'A' or 'a'. However, the program seems to be okay if the user enters uppercase choice. If a lower case choice is entered, gives the same reply two times. Give the line number(s) where error(s) occur and give correct code.
1.#include
3. int main() 4. { 5. char feedGrade;
6. // Get the desired grade of feed. 7. cout << "Our pet food is available in three grades: "; 8. cout << "A, B, and C. Which do you want pricing for? "; 9. cin >> feedGrade;
10. // Display the price. 11. switch(feedGrade) 12. { 13. case 'a': cout << "30 cents per pound. "; 14. case 'A': cout << "30 cents per pound. "; 15. break; 16. case 'b': cout << "20 cents per pound. "; 17. case 'B': cout << "20 cents per pound. "; 18. break; 19. case 'c': cout << "15 cents per pound. "; 20. case 'C': cout << "15 cents per pound. "; 21. break; 22. default: cout << "That is an invalid choice. "; 23. } 24. return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
