create a C++ program using Microsoft Visual Studio to do the following tasks:
Prompt the user for the salary per year and calculate a Christmas bonus based on the number of years worked as follow. Between 1 to 5 years 1% of salary, and more than five years 2% of salary. Any other values should be considered as an error message.
#include <iostream>
#include <string>
using namespace std;
int main() {
float salaryPerYear;
float christmasBonus=-1;
int numberYearsWorked;
cout<<"Ente the salary per year: ";
cin>>salaryPerYear;
cout<<"Ente the number of years worked: ";
cin>>numberYearsWorked;
if(numberYearsWorked>=1 && numberYearsWorked<=5){
christmasBonus=0.01*salaryPerYear;
}else if(numberYearsWorked>5 ){
christmasBonus=0.02*salaryPerYear;
}else{
christmasBonus=-1;
}
if(christmasBonus>0 && salaryPerYear>0){
cout<<"Christmas bonus: "<<christmasBonus<<"\n\n";
}else{
cout<<"Wrong data\n\n";
}
system("pause");
return 0;
}
Comments
Leave a comment