How do you write a program that displays the color of the item whose item number
ID: 3657271 • Letter: H
Question
How do you write a program that displays the color of the item whose item number is entered by the user. All item numbers contain exactly seven characters. All items are available in four colors: blue, green, red, and white. The fourth character in the item number indicates the item's color, as follows: a B or b indicates Blue, a G or g indicates Green, an R or r indicates Red, and W or w indicates White. If item number does not contain exactly seven characters, or if the fourth character is not one of the valid color characters, the program should display an appropriate message. Use a sentinel value to end the program. Test the program using the following item numbers: 123B567, 34AG123, 111r222, 123Explanation / Answer
#include #include #include using std:: cout; using std:: cin; using std:: endl; //function prototypes void getItemNumber void checkItemNumber int main() { //declare variables string item = ""; string item = ""; cout > item; while (item.length() != 5) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.