0% found this document useful (0 votes)
32 views2 pages

C++ Tasks

c++ loops
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

C++ Tasks

c++ loops
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like