A little help\question

Hi everyone! i just had a second lesson in C++ and i need your help!

I want to make this little thing that asks for the user name and i want that if my friend (shai natapov) will enter his name the program will say "Shai natapov detected!"

Anyway its not working here is what i did:(THANX FOR THE PPL WHO ANSWER :D)

#include <iostream.h>

int main () {
float name;


cout << "Hi there, what is your name?\n";
cin >> name;
cin.ignore();
if (name == shai natapov) {
cout << "Shai natapov detected!\n"

}


}
You can't store your name as a float.

You'll need to look at strings:
http://www.cplusplus.com/reference/string/string/
http://www.cplusplus.com/doc/tutorial/ntcs/
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>
using namespace std;

int main() {
    string name;
    getline(cin, name);
    if (name == "shai natapov") {
        cout << "Shai natapov detected!" << endl;
    }
}
Thank you :)
Using cin will stop your input once a whitespace is found. A whitespace can be a simple space, or a return character.
Thus if you enter two words, only the first will be read.
Getline solves this problem.
Topic archived. No new replies allowed.