-1

I'm new using C++, my instructor wants me to print this sentence:

A 6'2" person is 74.4 inches tall

The thing is I don't know how to put the quotes, and he doesn't let me use 6 and 2, he wants me to use the variable that I previously declared for 6'2". I don't have idea how to put quotes in a variable. Also that same variable that I previously declared as height_feet, it's been using to compute a calculation, so I can't declare it as string(can I?).

double height_feet = 6.2;
double height inches = height_feet * 12);
cout << "A " << height_feet << " person is " << height_inches<< " inches tall " << endl;
Damon9103
  • 1
  • 1

1 Answers1

2

You can escape them in a string like this:

  string height = "6\'2\"";
  cout << "A " << height << " person is " << 1.88<< " meters tall " << endl;

Just put a slash before " or ' which you want to include as part of the string rather than part of the code.

@iammilind pointed out that you don't technically require escaping for the single quote if it is between double quotes, so whether or not you escape that is optional.

Matthew Gaiser
  • 4,558
  • 1
  • 18
  • 35