Hi folks? I need an advise.
I have problem with code
I don't understand the matter of it doesn't work:
the problem is every time i see the finale line:
"I don't understand."
thank you so much
fiji885 (234) thanks fore help!
every time when i entered (c or i) or any other literal in "char a = ' ';" i have receive the same result "I don't understand"
Are you entering a number first as what I have done above? I haven't tested it with just by entering a character first. Post your input and output like what I have done above.
the book by Bjarne Stroustrup " The C++ Programming Language" chapter 4.4
The original code is a bit clearer than yours ("I don't know a unit called '" << unit << "'" outputs a clearer message):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int main()
{
constexprdouble cm_per_inch = 2.54; // number of centimeters in an inch
double length = 1; // length in inches or centimeters
char unit = 'a';
cout << "Please enter a length followed by a unit (c or i):\n";
cin >> length >> unit;
switch (unit) {
case'i':
cout << length << "in == " << cm_per_inch*length << "cm\n";
break;
case'c':
cout << length << "cm == " << length/cm_per_inch << "in\n";
break;
default:
cout << "Sorry, I don't know a unit called '" << unit << "'\n";
break;
}
}
Anyway, the book is “Programming: Principles and Practice Using C++” and the chapter is
4.4.1.2.