I just started reading this book and copy pasted this code from the PDF file:
// Read name and age (2nd version)
int main()
{
cout << "Please enter your first name and age\n";
string first_name = "???"; // string variable
// ("???” means “don’t know the name”)
int age = –1; // integer variable (–1 means “don’t know the age”)
cin >> first_name >> age; // read a string followed by an integer
cout << "Hello, " << first_name << " (age " << age << ")\n";
}
The book says it should output,
Hello, 22 (age –1)
if I input
22 Carlos
but I get this error:
D:\C++\Part I The Basics\Programs\3.Read name and age (2nd).cpp|9|error: stray '\226' in program|
And the program isn't compiling.
I realized that in the line below the "minus 1" isn't actually a "minus" "-" sign. .. " – " " - " It is bigger than the minus, see?
int age = –1
So I changed that sign with a minus sign and typed 22 Carlos and it outputs Hello 22, 0 instead of Hello 22, -1.
Why is the program not working when I simply copy-paste it from the PDF file?
Why is it not working even after I change the – sign with a minus "-" sign?