0

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";	   
	}
}
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by ziggazam
Featured Replies
  • This is what you want : [code] 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"; [/code] Read More

1

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";
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.