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;
}

Edited 6 Years Ago by Andreas5: n/a

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?

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
This question has already been answered. Start a new discussion instead.