Why won't this if statement compile?

int main1()
{
 char o[15];
 cin >> o;
 if(o == 'oscar')
 main2();
 else
 cout << "\n\aIncorrect password.\n" << endl;
 main();
   cin.clear();
   cin.ignore(255, '\n');
   cin.get();
   return 0;
}

I am trying to set a password to access the program

There are many things wrong with the code. Here is a code that does what you want, and looks almost the same:

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if(s == "oscar")
	;
	else{
		cout << "\n\aIncorrect password.\n" << endl;
		system("pause");
		return 0;
	}

	cout << "Correct Password" << endl;
	cin.clear();
	cin.ignore(255, '\n');
	cin.get();
	return 0;
}

so when assigning values to multiple character variables (like strings) you use double quotes? (" ") i never knew that

That works, thank you. Is it possible to make the characters you enter show up as stars, like it does when you log into most websites?

I dont know any simple way to do that.

Any complicated ways?

no:D

Double-Quotes ( " " ) are used to enter "string literals". Single-quotes are used to enter a single character i.e. 'C'

std::string myString = "This is a string literal, it uses double-quotes.";
char charString[80] = "This is also a string literal.";
char myChar = 'C' //this is a char literal

ah thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.