Answer to Question #161802 in C++ for Anonymous

Question #161802

This is a quick and easy program that will let you practice the basics of the switch statement.You will ask the user to enter a single-letter fabric code found on a pair of pants.You will then inform the user what material the pants are made out of.

 

Valid user entries are: 

 - 'C' for Cotton

 - 'L' for Liner

 - 'P' for Polyester

 

Prompt:

Enter the fabric code found on your pants: 

 

Possible Output:

Your pants contain cotton. Air dry to avoid shrinking!

Your pants contain linen. They are cool but wrinkle easily!

Your pants contain polyester. They are stain resistant!

Invalid fabric code. Please run the program again.

 

Notes and Hints:

1) You must accept the upper or lowercase version of the letters. Use whatever method you want of handling this.


1
Expert's answer
2021-02-12T07:24:33-0500
#include <iostream>
using namespace std;

int main() {
  char fabricCode;
  
  cout << "Enter the fabric code found on your pants: ";
  cin >> fabricCode;

  switch (fabricCode) {
    case 'C':
    case 'c':
      cout << "Your pants contain cotton. Air dry to avoid shrinking!\n";
      break;
    case 'L':
    case 'l':
      cout << "Your pants contain linen. They are cool but wrinkle easily!\n";
      break;
    case 'P':
    case 'p':
      cout << "Your pants contain polyester. They are stain resistant!\n";
      break;
    default:
      cout << "Invalid fabric code. Please run the program again.\n";
  }
  
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog