Here is my assignment:
Develop a program to generate a pay stub. Here’s an example stub:
Name: Doell, Susan
Employee id: SDoe0001
Gross Pay: $ 1099.15
Retire: $ 87.93
Tax: $ 141.57
Net Pay: $ 869.65
The program is to input an employee’s first, last name, and gross pay. The input is in a file. Here’s the input for the above example:
Susan Doell 1099.15
The retirement rate is 8%. Note that the retirement amount is subtracted from the gross pay before the tax is computed. The tax rate is 14%. The employee id is the first initial followed by the first three letters of the last name followed by "0001".
I think I need to use strings for the employee name part. I am horrible at math, and the arithmetic has me confused as well.
My second problem is this:
A cider market purchases apples in bags. How much is paid per bag is dependent on the condition of the apples as follows:
Condition Price per Bag
Good $12
Fair $9.50
A program is needed to prompt for and input the condition of a bag of apples and how many bags are to be purchased. The output is the total price. Here’s a sample run:
Enter apple condition: Fair
Enter how many bags: 4
The total price is $38.00
Condition Price per Bag
Excellent $14
Good $12
Fair $9.50
This program is almost done; here is what i have so far, l; HOWEVER, IT NEEDS A LOOP:
#include <iostream>
#include <string>
using namespace std;
const float EXCELLENT_COST = 14.0;
const float GOOD_COST = 12.0;
const float FAIR_COST = 9.5;
int main()
{
string condition;
int bags;
float costPerBag, totalCost;
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout << "Enter apple condition: ";
cin >> condition ;
cout << "Enter how many bags: ";
cin >> bags;
if (condition == ′"Excellent")
costPerBag = EXCELLENT_COST;
else
if (condition == "Good")
costPerBag = GOOD_COST;
else
costPerBag = FAIR_COST;
totalCost = costPerBag * bags;
cout << "The total price is $" << setprecision(2)
<< totalCost << endl;
return 0;
}
I need a loop so that if the user types something different for the apple condition, the program responds with a message that the input is not a valid one. In this case, the program is not to respond with a total price
Any help is highly appreciated.
Thank you,
- WFB.