What's wrong in my code?? #include using namespace std; int main () { int basicSalary, bonus = 0, years, newsalary; char gender; cout << "Enter the basic salary amount: "; cin >> basicSalary; cout << "Enter the number of years: "; cin >> years; cout << "Enter if the employee is F for Female or M for Male: "; if (years > 5 && gender == 'F') bonus = years * 20; else

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What's wrong in my code??

#include <iostream>

using namespace std;

int main ()
{
int basicSalary, bonus = 0, years, newsalary;
char gender;
cout << "Enter the basic salary amount: ";
cin >> basicSalary;
cout << "Enter the number of years: ";
cin >> years;
cout << "Enter if the employee is F for Female or M for Male: ";
if
(years > 5 && gender == 'F')
bonus = years * 20;
else
(years < 5 && gender == 'F')
bonus = years * 10;
else
(years > 5 && gender == 'M')
bonus = years * 40;
else
(years < 5 && gender == 'M')
bonus = years * 20;
newsalary = basicSalary + bonus cout << "Bonus amount is: " << bonus;
cout << "The new salary is " << newsalary;

return 0;
}

Expert Solution
Errors

1: First error is that you missed to input gender, after asking to input gender

2: To check for multiple condition you can use if/else if conditional statements, but here you used only if/else conditionals after which following else blocks are worthless and raising errors

3: Next, when you were assign values for newsalary you missed a semi-colon in the end

4: (optional) just for formatting purpose. For printing bonus and newsalary new line at the end to print them in a separate line

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education