need to enter more than one char input, not working

closed account (L092y60M)
Basically I'm having trouble reading more than one character.

I want the user to input character traits(ie, w, a), if two traits are entered they get the job.

But I cannot get my program to read more than one character input.

This is what I have so far... I'm stuck

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
#include <iostream>

using namespace std;

int main(){
char input;
	int count = 0;

	cout << "[s] mindful of safety, [w] work hard, [ww] work and play well with others, [m] self motivated / self starter" << endl;
	cout << "Please enter: " << endl;
	cin >> input;
	
	
	switch (input){
	case 's':
	case 'w':
		cout << "congrats you get the job!" << endl;
		break;
	case 'ww':
	default:
		cout << "bad input!";
		break;
	}

	cout << count << endl;


	system("pause");
	return 0;
}



I would really appreciate some input. Thank you
char, as its name tells you, can contain only one single character. You cannot place more than one in it. You should use strings for that.
closed account (L092y60M)
Ok then when I use a string... How will I break it up and compare characters?

Thanks.
As you wouldwith array elements, throught operator[].
You actually can compare whole strings:
1
2
3
4
5
6
std::string s;
std::cin >> s;
if (s == "w")
   //...
else if(s == "ww")
  //... 
closed account (L092y60M)
So if the user enters "a, w" and I run that through a if else statement like

String s;
Cin >> s

If (s==w) && (s==a)
Cout << "congrats";
Else
Cout << "goodbye";

I'm still getting nothing
If (s==w) && (s==a)

1) it is ill-formed. Case matters here and condition should be encased in parentheses.
2) What is w and aWhere are they declared?
3) One string cannot be equal to two different strings, in the same way there are no numbers which equals 3 and 4 simultaneously.
It looks like you want the user to enter a string in the format of "a, b, c" where 'a' 'b' and 'c' are whichever letters they want to input. Simply checking if the string is equal to any individual letter won't work if they decide to input more than one. You can either 1. Restrict input to to one letter 2. Divide the input string into an array of char's based on the commas inputted 3. Use string::find to check if the input contains a character without having to parse the string yourself. The last option would probably be the easiest, but you'll need to change your "ww" option to something else, otherwise input.find("w") will return true for the inputs 'w' and "ww" without being able to differentiate them.

Quick example of how to use find:
1
2
3
4
5
6
7
string input;
getline(cin,input);

if (input.find("w")!=string::npos)
{
    //we have a 'w' input
}


http://www.cplusplus.com/reference/string/string/find/
Topic archived. No new replies allowed.