1. Write if-else program to check if a person is eligible to vote.
2. If-else arithmetic operator
#include <iostream>
using namespace std;
int main()
{
float a, b, res;
char op;
cout << "Enter first number: " << endl;
cin >> a;
cout << "Enter second number: " << endl;
cin >> b;
cout << "Enter operator (+,-,*,/): " << endl;
cin >> op;
if (op == '+'){
res = a+b;
cout <<"Answer is: " << res << endl;
}
else if (op == '-'){
res = a-b;
cout <<"Answer is: " << res << endl;
}
else if (op == '*'){
res = a*b;
cout <<"Answer is: " << res << endl;
}
else if (op == '/'){
res = a/b;
cout <<"Answer is: " << res << endl;
}
else {
cout << "Wrong input!";
}
return 0;}
3. Logical operator discount code
#include <iostream>
using namespace std;
int age;
char isMember;
cout << "Enter your age: ";
cin >> age;
cout << "Are you a member? (Y/N): ";
cin >> isMember;
// Check if the customer is eligible for a discount
if (age >= 60 && (isMember == 'Y' && isMember == 'y')) {
cout << "You are eligible for a discount!" << endl;
}
else if (age >= 60 && (isMember == 'N' || isMember == 'n')){
cout << "You are not eligible for a discount." << endl;
}
else {
cout << "You are not eligible for a discount." << endl;
}
return 0;
}