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