...

View Full Version : Need help coding for homework -



WeezyF.Baby
10-12-2007, 11:22 AM
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.:confused:

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.

WorldEvolution
10-12-2007, 06:06 PM
I Had To Do This Same Project. Too Bad It's On My School Computer And I'm At Home. Thats Was One Of The First Things My Teacher Made Us Do In Java.

Inigoesdr
10-12-2007, 08:18 PM
Here is one way:


cout << "Enter apple condition: ";
cin >> condition;
while(condition != "Excellent" && condition != "Good") // whatever you're checking for
{
cout << "Invalid input" << endl;
cout << "Enter apple condition: ";
cin >> condition;
}
You may want to force the input to lower/uppercase for case-insensitive comparison. Also it looks like you have an extra character here:

if (condition == ′"Excellent")

WA
10-12-2007, 10:19 PM
Please read 1.5 on CF's rules page (http://www.codingforums.com/rules.htm). We can't help people actually do their homework- that's called cheating.

If you need help with a certain aspect of your homework, please post the code you're having trouble with, and explain what help you need. But asking people to basically do your assignment is not allowed.

Inigoesdr
10-12-2007, 10:56 PM
If you need help with a certain aspect of your homework, please post the code you're having trouble with, and explain what help you need. But asking people to basically do your assignment is not allowed.

I think that's what they did. They had already finished most of it, and just wanted help with one part.

Nightfire
10-12-2007, 11:14 PM
Problem now being, is that the solution is there for anyone that's doing the same class/course. I refuse to do any homework threads at all, as the next person that's too lazy to do anything has the finished script right infront of them and I dislike cheaters :D

Inigoesdr
10-13-2007, 12:37 AM
I see your point. If either of you feel that my response is or might be violating any rules, etc. feel free to delete it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum