switch statement

#include <strings.h>
#include <iostream>
using namespace std;

int main(){
bool ben;
ben = true;
while(ben == true){
int benslastname;

cout << "what is bens lastname? (1)newman (2)smith (3)lemonsqueesey" << endl;
cin >> benslastname;
switch (benslastname){

case 1:
cout << "WRONG!!!" << endl;
break;
case 2:
cout << "thats my name!" << endl;
break;
case 3:
cout << "correct!" << endl;
ben = false;
break;
default:
cout << "you didnt enter a name dummy!" << endl;
break;

}


}
return 0;
}
how can i get the program to run 'benslastname' as a string!?
closed account (1v5E3TCk)
you can try this

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
28
29
30
31
#include <strings.h>
#include <iostream>
using namespace std;

int main(){
bool ben;
ben = true;
while(ben == true){
string benslastname;

cout << "what is bens lastname? (1)newman (2)smith (3)lemonsqueesey" << endl;
cin >> benslastname;
if (benslastname=="newman")
cout << "WRONG!!!" << endl;
if (benslastname=="smith")
cout << "thats my name!" << endl;
break;
if (benslastname=="lemonsqueesey")
{cout << "correct!" << endl;
ben = false;}
else
cout << "you didnt enter a name dummy!" << endl;


}




return 0;
}
Topic archived. No new replies allowed.