The last employee data does not show when compiling the code - c++

I'm trying to obtain the data for the last employee Bob Hu. But for some reason, it doesn’t want to show up. Does anyone know what I'm doing wrong.? I try to put the calculation/display code into a function() and call it where you currently calculate/display the data and also after while() terminates. But I think I'm doing it wrong. Please help
This is my code.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void find_pay(string x)
{
ifstream inputFile;
string filename;
// Get the filename from the user.
cout << "Enter the filename: ";
cin >> filename;
// Open the file.
inputFile.open(filename);
// If the file successfully opened, process it.
if(inputFile.is_open())
{
string data_record,prev,data_name,data_hour;
double total = 0;
while(getline(inputFile,data_record))
{
data_name = data_record.substr(0,30);
data_hour = data_record.substr(31,2);
if(prev.compare(data_name)!= 0 )
{
//Calculate the gross pay, tax, net pay
float gross_pay = 18 * total;
float tax = (12 * gross_pay)/100;
float net_pay = gross_pay - tax;
if(total!= 0)
cout << "Employee:" << prev << "\n" "Total Hours: " << total << " Gross Pay: $ " << gross_pay << " Tax " << tax << " Net Pay: " << net_pay << endl;
data_name = data_record.substr(0,30);
prev = data_name;
total = 0;
}
else if(prev.compare(data_name)==0)
{
total += stod(data_hour);
}
}
//close the file
inputFile.close();
}
}
int main()
{
string filename;
find_pay(filename); //call the void
return 0;
}
This is the output that I got, as you see Bob Hu is missing
Enter the filename: /Users/normatacuri/Desktop/employeehours.txt
Employee:Jimmy Bucket
Total Hours: 26 Gross Pay: $ 468 Tax 56.16 Net Pay: 411.84
Employee:John Doe
Total Hours: 32 Gross Pay: $ 576 Tax 69.12 Net Pay: 506.88
Employee:Ann Doe
Total Hours: 20 Gross Pay: $ 360 Tax 43.2 Net Pay: 316.8
Employee:Mary Jones
Total Hours: 16 Gross Pay: $ 288 Tax 34.56 Net Pay: 253.44
Program ended with exit code: 0
This is the data on the file that I'm using..
Jimmy Bucket 8
Jimmy Bucket 9
Jimmy Bucket 10
Jimmy Bucket 7
John Doe 8
John Doe 8
John Doe 8
John Doe 8
John Doe 8
Ann Doe 5
Ann Doe 5
Ann Doe 5
Ann Doe 5
Ann Doe 5
Mary Jones 4
Mary Jones 4
Mary Jones 4
Mary Jones 4
Mary Jones 4
Bob Hu 8
Bob Hu 8
Bob Hu 8
Bob Hu 8
Bob Hu 8

I try to put the calculation/display code into a function() and call it where you currently calculate/display the data and also after while() terminates. But I think I'm doing it wrong.
You are right, you must have done it wrong, but your approach of handling the case also after while() terminates was good. Since you don't show this try, I can't say what you were doing wrong. But I can show you an alternative approach where the EOF case is also handled inside the loop - for this replacement of the while loop only a few statements have to be rearranged.
for (; ; )
{ bool f = (bool)getline(inputFile, data_record);
if (!f || prev.compare(data_name = data_record.substr(0, 30)) != 0)
{ // do this on EOF as well as new name
//Calculate the gross pay, tax, net pay
float gross_pay = 18 * total;
float tax = (12 * gross_pay)/100;
float net_pay = gross_pay - tax;
if (total != 0)
cout << "Employee:" << prev << "\n"
"Total Hours: " << total << " Gross Pay: $ " << gross_pay
<< " Tax " << tax << " Net Pay: " << net_pay << endl;
if (!f) break;
prev = data_name;
total = 0;
}
total += stod(data_hour = data_record.substr(31, 2));
}

Related

C++ Overtime / Payroll / Time and a half/ Double Time

i know my if statement is not correct somewhere but i do not know where? or maybe its just the logical error?
After 8 hours any hours worked will be paid time and a half. That is, given the wage per hour multiply by 1.5. That wage is paid for hours after 8 hours.
After 10 hours any hours worked will be paid double time. That is, given the wage per hour multiply by 2.0. That wage is paid for hours after 10 hours.
Please show: ( Example output )
Wage per hour: 12.37
Hours worked : 10.3
Pay for ( 0 to 8 hours) : 98.96
Pay for hours 8 to 10) : 37.11
Pay for hours (10 and beyond): 7.42
Total Gross Pay : 143.49
// Example program
#include <iostream>
#include <string>
using namespace std;
double HoursWorked;
double WagePerHour;
double TotalWages;
double TimeAndHalf;
double Overtime;
char ContinueChar;
//test cases: 10.5 hours # 12/hour = $96.00, 2 hours at 1.5 rate = $36.00, .5 hour at 2.0 rate = $12.00
// 6.3 hours # 12/hour = 75.6, no hours of overtime or double time
//12.5 hours # 14.34/ hour = $114.72, 2 hours at 1.5 rate = 43.02, 2.5 hours at 2.0 rate = $71.70
//3.7 hours # 19/hour = $70.30
// 14 hours # 23.50/hour = $188, 2 hours at 1.5 rate = $70.50, 4 hours at 2.0 rate = $188
//I tested with test test cases and the program had the same results.
int main()
{
cout << "Ticket #64220\n";
cout << "CMPR-120\n";
cout << "Instructor : Joel Kirscher\n";
cout << "Student: Seyed Shariat\n";
cout << "Payroll Overtime";
cout << "\n\n";
do {
cout << "How many hours did you work this pay period: \n";
cin >> HoursWorked;
cout << "What wage do you get paid per hour?: \n";
cin >> WagePerHour;
cout << "So you your paycheck will be: " << HoursWorked * WagePerHour << " before taxes are taken out. \n";
if (HoursWorked > 8 && <= 10)
cout << "For the hours you worked over 8, and less than or equal to 10 you made: " << HoursWorked * 1.5 * WagePerHour << " \n";
else (HoursWorked >10);
cout << "For the hours you worked over 10: " << HoursWorked * 2.0 * WagePerHour << " \n";
cout << "Do you want this to run again? (y=Yes): ";
cin >> ContinueChar;
} while (ContinueChar == 'y' || ContinueChar == 'Y');
cin.get();
return 0;
}
There are many approaches to this. Here is one. The comments may help you to follow my reasoning. Fortunately the mathematics behind this is not very complicated.
/*
We need to find the area under this pay rate / hours worked graph.
The following approach divides the graph into three rectangles as shown below
2.0 | +--+
| | |
1.5 | +-+--|
| | |
1.0 +-------+----|
| |
0.5 | |
| |
0.0 +------------+
0 8 10
*/
// Calculate basic pay before any overtime consideration
Pay = HoursWorked * HourlyRate;
// Hours above 8 earn half-again more than the standard wage.
// (This will be only positive if more than 8 hours were worked.)
OvertimePay = (HoursWorked - 8.0) * HourlyRate * 0.5;
if(OvertimePay > 0.0)
Pay += OvertimePay;
// Hours above 10 earn an additional 50% extra
// (This will be only positive if more than 10 hours were worked.)
OvertimePay = (HoursWorked - 10.0) * HourlyRate * 0.5;
if(OvertimePay > 0.0)
Pay += OvertimePay;

C++ File I/O skipping line every new iteration, why?

Why is the program skipping the first line of every new deptnum?
I am trying to read from a file that looks like:
1 Suits 0300 100 092
1 Coats 0200 060 065
1 Shirts 1000 012 013
2 Dresses 0400 060 065
2 Coats 0185 184 200
2 Shoes 0600 040 030
3 Jeans 0200 040 035
3 Shoes 0200 030 034
4 Jeans 0300 042 043
The deptnum is the first column.
And when I write to the other file I get:
Blinn Discount Apparel Company
Inventory Evaluation
10/12/2018
Unit Cost Extended
Quantity Cost Market Cost Market Lower Cost
Mens Dept
Suits 300 100.00 92.00 30000.00 27600.00
Coats 200 60.00 65.00 12000.00 13000.00
Shirts 1000 12.00 13.00 12000.00 13000.00
Total $54000.00 $53600.00 $53600.00
Womens Dept
Coats 185 184.00 200.00 34040.00 37000.00
Shoes 600 40.00 30.00 24000.00 18000.00
Total $112040.00 $108600.00 $108600.00
Girls Dept
Shoes 200 30.00 34.00 6000.00 6800.00
Total $118040.00 $115400.00 $115400.00
Boys Dept
Total $118040.00 $115400.00 $115400.00
Total Inventory $393000.00
It skipped Womens Dept -> Dresses, Girls Dept -> Jeans, and Boys Dept -> Jeans.
Here is my code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
int x = 1, deptnum, quant,cost,mkt,extcost,extmkt,totalcost = 0,totalmkt = 0,
lowcost,totalInv = 0;
char item [15];
inFile.open("blinn.dat");
outFile.open("blinn.dout");
if (!inFile)
cout <<"\n\t\t Can't open data file: blinn.dat\n";
else {
outFile <<"\n\t Blinn Discount Apparel Company\n";
outFile <<"\t Inventory Evaluation\n";
outFile <<"\t 10/12/2018\n";
outFile <<"\n\t\t\t\t\t\t Unit Cost\t\t\t Extended\n";
outFile <<"\t\t Quantity Cost Market Cost Market Lower Cost";
while (x < 5)
{
if (x == 1)
outFile << "\nMens Dept";
else if (x == 2)
outFile << "\nWomens Dept";
else if (x == 3)
outFile << "\nGirls Dept";
else if (x == 4)
outFile << "\nBoys Dept";
else
break;
while (inFile >> deptnum >> item >> quant >> cost >> mkt)
{
if (deptnum == x){
extcost = quant * cost;
extmkt = quant * mkt;
outFile << left << "\n " << setw(7)<< item << " "
<< right << setw(4)<< quant << " "
<< right << setw(4) << cost << ".00 "
<< right << setw(3) << mkt << ".00 "
<< right << setw(5) << extcost<< ".00 "
<< right << setw(5) << extmkt << ".00";
totalcost += extcost;
totalmkt += extmkt;
if (totalcost > totalmkt)
lowcost = totalmkt;
else
lowcost = totalcost;
}else
break;
}
outFile << right << "\n Total\t\t\t\t\t $" << totalcost << ".00 $"
<< totalmkt << ".00 $"<< lowcost << ".00";
x += 1;
totalInv += lowcost;
}
}
outFile << "\nTotal Inventory\t\t\t\t\t\t $"<< totalInv<< ".00";
inFile.close ();
outFile.close ();
return 0;
}
What is wrong with my logic?
There is a problem with your logic:
if (deptnum == x) {
// do something
}
else {
break;
}
To achieve the else branch, you have already read a line that deptnum != x (the first line of every new deptnum) so at the next iterator, the current line is discarded by the next input line.

Values not assigning correctly in 2d array

I'm at my wits end, and I'm sure it's a simple mistake. I've googled this and I've seen this similar problem presented a number of times, but my code looks similar to what I've seen so I still can't figure out what I've done wrong.
I'm working on a homework assignment for a class that asks a user for amounts of food eaten by 3 monkeys over the course of a week and then stores those entries in a 2d array.
Please forgive my horrible variable names, I'm going to change them once I break this out into different functions, but I wanted to get it running in main first. I've tested it and my sum, average, least, and most statements work, but for some reason the data I'm entering into the array is skipping numbers or overwritting numbers (I've posted an output below as well).
When I run the code:
#include // for cin, cout, endl
#include
#include
using namespace std;
const int DAYS_WEEK = 7;
const int MONKEYS = 3;
int main()
// main function
{
// One dimensional array just to prove I could do it. Also it holds the names of the days of the week, for the cout statement below that asks for input
string dayOfWeek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
//2d array that will store the food eaten by each monkey as it is entered in by the user below
double foodEaten[DAYS_WEEK][MONKEYS];
//value to store the sum of all the food eaten by all monkeys
double total = 0;
//count to keep track of how many times the sum loop runs below, so I can use it as the divisor to find the average
int count = 0;
//value to hold the average once found
double average = 0;
//value to hold the least amount of food eaten
double least = 0;
//value to hold the highest amount of food eaten
double most = 0;
//This nested loop asks for input from the user and should input the values entered into the two dimensional array
for ( int monkey = 0; monkey < MONKEYS; monkey++ )
{
for ( int day = 0; day < DAYS_WEEK; day++ )
{
cout << "Enter pounds of food eaten by monkey "
<< (monkey + 1)
<< " on " << dayOfWeek[day] << ": " ;
cin >> foodEaten[monkey][day];
//This will double check that the user hasn't entered a negative number and if they have throw them back into the loop
while ( foodEaten[monkey][day] < 0 )
{
cout << "Enter a non-negative amount: ";
cin >> foodEaten[monkey][day];
}
}
cout << endl;
}
//This should display the table of how much food was eaten after it is all entered
cout << setw(6) << "Monkey"
<< setw(5) << "Sun"
<< setw(5) << "Mon"
<< setw(5) << "Tue"
<< setw(5) << "Wed"
<< setw(5) << "Thu"
<< setw(5) << "Fri"
<< setw(5) << "Sat" << endl;
for ( int monkeyLord = 0; monkeyLord <= 2; monkeyLord++)
{
cout << setw(6) << (monkeyLord + 1) << setw(5) << foodEaten[monkeyLord][0] << setw(5) << foodEaten[monkeyLord][1] << setw(5) << foodEaten[monkeyLord][2] << setw(5) << foodEaten[monkeyLord][3] << setw(5) << foodEaten[monkeyLord][4] << setw(5) << foodEaten[monkeyLord][5] << setw(5) << foodEaten[monkeyLord][6] << endl;
}
//This should sum all the amounts of food eaten by the monkeys
for ( int monkeyTotal = 0; monkeyTotal <= 2; monkeyTotal ++)
{
for ( int dayTotal = 0; dayTotal <= 6; dayTotal ++)
{
total = total + foodEaten[monkeyTotal][dayTotal];
count++;
}
}
//This should find the average amount of food eaten
average = total/count;
cout << "The average food eaten per day by all monkeys :" << setw(6) << average << " pounds" << endl;
//This shoud find the least amount of food eaten
least = foodEaten[0][0];
for ( int monkeyLeast = 0; monkeyLeast <= 2; monkeyLeast ++ )
{
for ( int dayLeast = 0; dayLeast <= 6; dayLeast ++ )
{
if ( foodEaten[monkeyLeast][dayLeast] < least )
least = foodEaten[monkeyLeast][dayLeast];
}
}
cout << "The least amount of food eaten by any monkey :" << setw(6) << least << " pounds" << endl;
//This should find the highest amount of food eaten
most = foodEaten[0][0];
for ( int monkeyMost = 0; monkeyMost <= 2; monkeyMost ++ )
{
for ( int dayMost = 0; dayMost <= 6; dayMost ++ )
{
if ( foodEaten[monkeyMost][dayMost] > most )
most = foodEaten[monkeyMost][dayMost];
}
}
cout << "The largest amount of food eaten by any monkey :" << setw(6) << most << " pounds" << endl;
return 0;
}
For some reason this is what my output looks like:
Enter pounds of food eaten by monkey 1 on Sun: 1
Enter pounds of food eaten by monkey 1 on Mon: 2
Enter pounds of food eaten by monkey 1 on Tue: 3
Enter pounds of food eaten by monkey 1 on Wed: 4
Enter pounds of food eaten by monkey 1 on Thu: 5
Enter pounds of food eaten by monkey 1 on Fri: 6
Enter pounds of food eaten by monkey 1 on Sat: 7
Enter pounds of food eaten by monkey 2 on Sun: 8
Enter pounds of food eaten by monkey 2 on Mon: 9
Enter pounds of food eaten by monkey 2 on Tue: 10
Enter pounds of food eaten by monkey 2 on Wed: 11
Enter pounds of food eaten by monkey 2 on Thu: 12
Enter pounds of food eaten by monkey 2 on Fri: 13
Enter pounds of food eaten by monkey 2 on Sat: 14
Enter pounds of food eaten by monkey 3 on Sun: 15
Enter pounds of food eaten by monkey 3 on Mon: 16
Enter pounds of food eaten by monkey 3 on Tue: 17
Enter pounds of food eaten by monkey 3 on Wed: 18
Enter pounds of food eaten by monkey 3 on Thu: 19
Enter pounds of food eaten by monkey 3 on Fri: 20
Enter pounds of food eaten by monkey 3 on Sat: 21
Monkey Sun Mon Tue Wed Thu Fri Sat
1 1 2 3 8 9 10 15
2 8 9 10 15 16 17 18
3 15 16 17 18 19 20 21
The average food eaten per day by all monkeys :12.7143 pounds
The least amount of food eaten by any monkey : 1 pounds
The largest amount of food eaten by any monkey : 21 pounds
--------------------------------
Process exited after 19.28 seconds with return value 0
Press any key to continue . . .
You can see starting on Wednesday of the first row that the data is not mirroring what I entered and it happens again on the second row, but not the third.
Thanks for any help.
You need to access
foodEaten[day][monkey]
not
foodEaten[monkey][day]
This is the solution: you should replace this line: double foodEaten[DAYS_WEEK][MONKEYS]; with this double foodEaten[MONKEYS][DAYS_WEEK];
here is the output:
The Problem you are facing is that :
In effect your Array is:
double foodEaten[7][3]
But when you Access the elements it is in the following order:
foodEaten[Monkey][DayOfTheWeek]
Always ensure logical consistency in your array, i.e if your rows are Days and your columns Monkeys, ensure your iterators are also of the same type.
As the other answers have specified, using
foodEaten[DayOfTheWeek][Monkey]
would solve the problem.

Is there a calculation error in my program?

Apparently there is a calculation error somewhere in my program, but I simply can’t find it.
The only information I have as to why there is a calculation error is this following feedback given by MyProgrammingLab (A site that automatically tests code to see if it's incorrect or not). I don't know what values were entered for the annual death rate and annual birth rate to cause it. Could it be that I'm right but MyProgrammingLab is wrong? Honestly, all my own tests seem fine.
Expected Output:
Year 1: 200 176
Year 2: 176 154
Year 3: 154 135
Year 4: 135 118
Year 5: 118 103
Year 6: 103 90
Year 7: 90 79
Actual Output:
Year 1: 200 199
Year 2: 199 198
Year 3: 198 197
Year 4: 197 196
Year 5: 196 195
Year 6: 195 194
Year 7: 194 193
I built the program according to the following assignment:
In a population, the birth rate is the percentage increase of the population due to births, and the death rate is the percentage decrease of the population due to deaths. Write a program that asks for the following:
The starting size of a population (minimum 2) (Prompt Enter starting size:)
The annual birth rate (Prompt Enter annual birth rate:)
The annual death rate (Prompt Enter annual death rate:)
The number of years to display (minimum 1) (Prompt Enter years to display:)
The program should then display the starting population and the projected population at the end of each year. It should use a function that calculates and returns the projected new size of the population after a year. The formula is
N = P(1 + B)(1 - D)
where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate. Annual birth rate and death rate are the typical number of births and deaths in a year per 1000 people, expressed as a decimal. So, for example, if there are normally about 32 births and 26 deaths per 1000 people in a given population, the birth rate would be .032 and the death rate would be .026.
My code:
#include <iostream>
using namespace std;
int projectedNewSize(float population, float annualBirthRate, float annualDeathRate) {
float annualBirthRate2 = annualBirthRate / 1000;
float annualDeathRate2 = annualDeathRate / 1000;
int newpopulation = population * (1 + annualBirthRate2) * (1 - annualDeathRate2);
return newpopulation;
}
int main() {
int populationStartingSize = 0;
float annualBirthRate = 0;
float annualDeathRate = 0;
int numberOfYearsToDisplay = 0;
do {
cout << "Enter starting population size: ";
cin >> populationStartingSize;
cout << "Enter annual birth rate: ";
cin >> annualBirthRate;
cout << "Enter annual death rate: ";
cin >> annualDeathRate;
cout << "Enter years to display: ";
cin >> numberOfYearsToDisplay;
} while (!(populationStartingSize >= 2) || !(numberOfYearsToDisplay >= 1));
int population;
for (int i = 1; i <= numberOfYearsToDisplay; i++) {
cout << "Year " << i << ": " << populationStartingSize << " ";
population = projectedNewSize(populationStartingSize, annualBirthRate, annualDeathRate);
cout << population << endl;
populationStartingSize = population;
}
system("pause");
return 0;
}
So, The answer is
There is no need to divide the annualBirthRate and the annualDeathRate by 1000. Since annualBirthRate is calculated as annual births per 1000 of a population, It need not be divided by 1000 again.
Thus removing these lines
float annualBirthRate2 = annualBirthRate / 1000;
float annualDeathRate2 = annualDeathRate / 1000;
and changing
int newpopulation = population * (1 + annualBirthRate2) * (1 - annualDeathRate2);
to
int newpopulation = population * (1 + annualBirthRate) * (1 - annualDeathRate);
So, the final code would look like this:
#include <iostream>
using namespace std;
int projectedNewSize(float population, float annualBirthRate, float annualDeathRate) {
int newpopulation = population * (1 + annualBirthRate) * (1 - annualDeathRate);
return newpopulation;
}
int main() {
int populationStartingSize = 0;
float annualBirthRate = 0;
float annualDeathRate = 0;
int numberOfYearsToDisplay = 0;
do {
cout << "Enter starting population size: ";
cin >> populationStartingSize;
cout << "Enter annual birth rate: ";
cin >> annualBirthRate;
cout << "Enter annual death rate: ";
cin >> annualDeathRate;
cout << "Enter years to display: ";
cin >> numberOfYearsToDisplay;
} while (!(populationStartingSize >= 2) || !(numberOfYearsToDisplay >= 1));
int population;
for (int i = 1; i <= numberOfYearsToDisplay; i++) {
cout << "Year " << i << ": " << populationStartingSize << " ";
population = projectedNewSize(populationStartingSize, annualBirthRate, annualDeathRate);
cout << population << endl;
populationStartingSize = population;
}
system("pause");
return 0;
}
You guys discussed in the comments section and left the question unanswered..
int projectedNewSize(float population, float annualBirthRate, float annualDeathRate) {
int newpopulation = roundf(population * (1.0 + annualBirthRate) * (1.0 - annualDeathRate);
return newpopulation;
}
In the calculatiton you dont have to consider the factor of 1000 if it is already done in the input values. But if you want a 'most accurate' table you have to round the values in a proper mind. The return of the calculation is a float. If you assign it to an int - it always will be truncated. A little difference wich will be carried over from one loop to the next, ending up in some reasonable differences to the expected values at the end. The most proper way would be to change the type of 'newcalculation' to float and round only when display the value.
N = P + BP - DP
Program asked for birthrate and death rate, assume user entered 5 for 5%.
Basic math needs to be calculated here 5/100 = 0.05
The formula is now
N = P + (BP/100) - (DP/100)
Replace
float annualBirthRate2 = annualBirthRate / 1000;
float annualDeathRate2 = annualDeathRate / 1000;
int newpopulation = population * (1 + annualBirthRate2) * (1 - annualDeathRate2);
With
int newpopulation = population + (population * birthRate/100) - (population * deathRate/100)

Salary calculator (over time pay) require assistance of senior level programmers

4.16 (Salary Calculator) Develop a C++ program that uses a while statement to determine the
gross pay for each of several employees.
When someone works 41 hours or more. They get paid 1.5x more so my problem is that in my else if statement. I did rate * 1.5 which should translate into 10 * 1.5 = 15 but I get 425 because my code on the top probably, but I don't understand it at the moment.
He gave us this example. Which I'm trying to emulate.
"
Enter hours worked (-1 to end): 41
Enter hourly rate of the employee ($00.00): 10.00
Salary is $415.00
"
#include <iostream>
using namespace std;
int main()
{
double salary=0,rate=0,hours=0,counter=0;
cout << "Enter your hours worked: ";
cin >> hours;
cout << "Enter your rate: ";
cin >> rate;
while(counter<=hours)
{ salary=hours*rate;
counter++;
}
if(hours==-1)
{exit(0);
}
else if(hours>=41)
{
rate = rate * 1.5;
salary = salary + rate;
}
cout << "$" << salary;
return 0;
}
The loop you used has no functionality related to the problem, so I omitted it. Below is what will work. As others have said, define why you need a loop. I'm guessing you need to loop the code so the user can repeat this to their heart's content. If that is the case, I'll let you try to figure out how to break out of the loop when a user enters -1.
if (hours == -1)
exit(0);
else if (hours <= 40)
salary = rate * hours;
else {
double overtimeHours = hours - 40;
salary = rate * 40;
rate = rate * 1.5;
salary = salary + (rate * overtimeHours);
}
cout << "$" << salary;