Switch statement

I am working on the question from this post:

http://www.cplusplus.com/forum/beginner/182764/

I thought I had correctly made the changes listed in the reply, but I am still coming up with three errors. The errors are in lines 15 saying no operator "<<" matches these operands. and line 35 saying expression must have an integral or unscoped enum type and cannot determine which instance of function template "std::endl" is intended.

I am using visual studio. This is my first post and I am extremely new to programming in general so any help would be greatly appreciated.



#include <iostream>

using namespace std;

string number (int a);


int main()
{
int num;
string word;
cout << "Enter an integer number between 1 and 5.\n";
cin >> num;
word = number(num);
cout << "You entered " << word << endl;

return 0;
}

string number (int a)
{
switch (a)
{
case 1:
return "one";
case 2:
return "two";
case 3:
return "three";
case 4:
return "four";
case 5:
return "five";
default:
return "invalid number." << endl;
system("pause");

}
}
#include <string>
Cannot use insertion operator, <<, on a string.

Replace

return "invalid number." << endl;'

with

return "invalid number.\n";

\n is escape sequence for newline.
Last edited on
Topic archived. No new replies allowed.