0% found this document useful (0 votes)
19 views3 pages

SAMPLE CODE DISCUSSION REVIEW of C

The document contains 4 code snippets that demonstrate basic payroll calculations, conditional logic for job eligibility, and ternary operators. The first code snippet calculates monthly and annual gross income, deductions, taxes, and net pay for an employee. It uses inputted values for name, daily rate, and number of days worked. The second snippet uses conditional logic and both relational and logical operators to check if an applicant meets age, salary, and experience requirements for a job. The third and fourth snippets are examples of ternary operators to check eligibility to vote based on age and eligibility for a senior discount based on age respectively.

Uploaded by

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

SAMPLE CODE DISCUSSION REVIEW of C

The document contains 4 code snippets that demonstrate basic payroll calculations, conditional logic for job eligibility, and ternary operators. The first code snippet calculates monthly and annual gross income, deductions, taxes, and net pay for an employee. It uses inputted values for name, daily rate, and number of days worked. The second snippet uses conditional logic and both relational and logical operators to check if an applicant meets age, salary, and experience requirements for a job. The third and fourth snippets are examples of ternary operators to check eligibility to vote based on age and eligibility for a senior discount based on age respectively.

Uploaded by

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

BASIC PAYROLL

#include <iostream>
using namespace std;

int main()
{
// Declaration of variables
string name;
float rate, day, grossm, grossy, fixd, tax, taxm, sss=500, pag=100, phil=400, totaldwt, totaldl;

// Prompting user for input


cout<<"Enter Complete Name: "<<endl;
getline(cin, name); // Taking input for name

cout<<"Enter Daily Rate: "<<endl;


cin>>rate; // Taking input for daily rate

cout<<"Enter No. of Days Present: "<<endl;


cin>>day; // Taking input for number of days present

// Calculating monthly and annual gross income


grossm= rate*day;
grossy=grossm*12;

fixd=sss+pag+phil; // Calculating fixed deductions


tax=grossy*0.15; // Calculating tax
taxm = tax/12; // Calculating monthly tax
totaldwt=fixd+taxm; // Calculating total deductions

// Output section
cout<<"_______________________________"<<endl;
cout<<"PAYROLL of "<<name<<endl;
cout<<"Gross Income(Monthly): "<<grossm<<endl;
cout<<"Gross Income(Annual): "<<grossy<<endl;

// Conditional section for tax calculation


if (grossy>500000){
cout<<"Tax(Annual): "<<tax<<endl;
cout<<"Tax Monthly: "<<taxm<<endl;
cout<<"Total Deduction (TaxM+SSS+Pag-ibig+Philhealth): "<<totaldwt<<endl;
cout<<"Net Take Home Pay: "<<grossm-totaldwt<<endl;
}
else {
cout<<"Total Deduction(SSS,Pag-ibig,Philhealth): "<<fixd<<endl;
cout<<"Tax: 0%"<<endl;
cout<<"Net Take Home pay: " <<grossm-fixd<<endl;
}
return 0; // End of main function
}

SALARY

#include <iostream>
using namespace std;

int main() {
string name;
int age;
int salary;
bool hasExperience;

// Prompting user for input

cout<<"Enter Complete Name: "<<endl;


getline(cin, name);

cout << "Enter your age: ";


cin >> age;

cout << "Enter your monthly salary: ";


cin >> salary;

cout << "Do you have relevant experience? (1 for Yes, 0 for No): ";
cin >> hasExperience;

cout<<"___________________________________________________"<<endl;

// Conditional statement using both relational and logical operators


if (age >= 18 && salary > 25000 && hasExperience) {
cout << "Hello "<< name << " your are eligible for the job" << endl;
} else {
cout << "Hello "<< name <<" your not eligible for the job" << endl;
}

return 0;
}

TERNARY 1

#include <iostream>
using namespace std;
int main() {
int age;

// Prompting user for input


cout << "Enter your age: ";
cin >> age;

// Ternary operator example


//string eligibility = (age >= 18) ? "You are eligible to vote" : "You are not eligible to vote";
age >= 18 ? cout<<"You are eligible to vote " : cout<<"You are not eligible to vote ";

// Output the result


//cout << eligibility << endl;

return 0;
}

TERNARY 2

#include <iostream>
using namespace std;

int main() {
int age;

// Prompting user for input


cout << "Enter your age: ";
cin >> age;

// Ternary operator example with a boolean data type


bool isEligibleForDiscount = (age >= 60) ? true : false;

// Output the result


if (isEligibleForDiscount) {
cout << "Congratulations! You are eligible for a senior citizen discount." << endl;
} else {
cout << "Sorry, you are not eligible for a senior citizen discount." << endl;
}

return 0;
}

You might also like