Vote or Not

Q.Enter the name,nationality and age of a Person.If the age is greater than 18 and Nationality is Indian,then you can Vote otherwise you cannot vote.Write a Program in C++ for this.
Ans
//Vote or Not
#include<iostream>
#include<string>
using namespace std;
int main()
{

string SN,Nationality;
int Age;
cout<<"Enter Student Name:"<<endl;
getline(cin,SN);
cout<<"Enter Nationality:"<<endl;
cin>>Nationality;
cout<<"Enter Age:"<<endl;
cin>>Age;
if(Age>18&&Nationality="Indian")
cout<<"You can Vote ";
else
cout<<"You can not Vote";
return 0;


}


It shows compilation error.Please help me to correct it.Thanx.
Go and learn how to do your brackets before trying to make a program....
Besides, use code tags, the <> beside the textbox.
However, I am nice, so this is the working code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
using namespace std;

int main()
{

	string SN;
	string Nationality;
	int Age;
	cout<< "Enter Student Name:" <<endl;
	cin >> SN;
	cout<<"Enter Nationality:"<<endl;
	cin >> Nationality;
	cout<<"Enter Age:"<<endl;
	cin>>Age;
	if(Age >  18 && Nationality == "Indian")
	{
		cout<<"You can Vote ";
	}else
	{
		cout<< "You can not Vote" << endl;
	}
	system("PAUSE");

}

Last edited on
Looked pretty good for the most part- just don't forget the difference between = and ==.
When you use one equal sign, you're setting the variable to whatever is to the right of the equal sign.
ex: x = 5;

If you want to ask the compiler to check whether or not two things are equal, you'll need to use two equal signs.
ex: if(a == 5)
do cool stuff;

Otherwise, looked spot on.
Topic archived. No new replies allowed.