Oct 21, 2010 at 7:47pm UTC
I know this is stupid.. im trying to get a switch statement to work.. for learning purposes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name1;
cout<<"Enter a name: " <<endl;
cin>>name1;
switch (name1){
case 'Brian' :
case 'brian' :
cout<<"Brian Kiani" <<endl;
break ;
defualt:
break ;
}
return 0;
}
1 2 3 4 5 6 7
||In function `int main()':|
|12|error: switch quantity not an integer|
|14|warning: multi-character character constant|
|15|warning: multi-character character constant|
||=== Build finished: 1 errors, 2 warnings ===|
Why am I getting the error and the 2 warnings?
Last edited on Oct 21, 2010 at 7:50pm UTC
Oct 21, 2010 at 7:52pm UTC
You can only use a an integer variable for a switch statement. Also, between two single quotes, there has to be a single character (escape sequences such as '\n' are exceptions).
Finally, it's default
, not defualt
.