Hi i am new to programming and i decided to go straight to C++ and i am starting to grasp it. so i am trying random codes using my current knolage(Bad spelling) to make them. But i am trying an if else statement using my name and my brothers name. I will link it in a sec but my problem is I can't get it to compile as soon as I put the if else statement. here is my code (The names are changed because i don't want to show mine on public forums, the names aren't actually key words on the normal code lol)

#include <iostream>

int main()
{
	int name;
	int myName;
	int Bro's name;
	using namespace std;
	cout<< "Hello type you name: ";
	cin>> name;
	if name == myName;{ 
	cout<< "Welcome !";
	}
	if else ( name == bro's name ); {
	cout<< "hello";	   
	}
}

This is what you want :

string myName = "josh";
string myBrotherName = "tommy";
string input;

cout << "Enter a name : ";
cin >> input;

if(input == myName){
 cout << "Welcome admin\n";
}
else if(input == myBrotherName){
 cout  << "Welcome guest\n";
}
else cout << "Invalid user\n";

Line 14.

else if( name == bro's name );

This is what you want :

string myName = "josh";
string myBrotherName = "tommy";
string input;

cout << "Enter a name : ";
cin >> input;

if(input == myName){
 cout << "Welcome admin\n";
}
else if(input == myBrotherName){
 cout  << "Welcome guest\n";
}
else cout << "Invalid user\n";

Thanks
Didn't know i needed a string to do this
The only examples ive seen are number ones

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.