Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-12-2007, 11:22 AM   PM User | #1
WeezyF.Baby
New to the CF scene

 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
WeezyF.Baby is an unknown quantity at this point
Question Need help coding for homework -

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.
WeezyF.Baby is offline   Reply With Quote
Old 10-12-2007, 06:06 PM   PM User | #2
WorldEvolution
New Coder

 
Join Date: Oct 2007
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
WorldEvolution is an unknown quantity at this point
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.
WorldEvolution is offline   Reply With Quote
Old 10-12-2007, 08:18 PM   PM User | #3
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Here is one way:
Code:
	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:
Code:
if (condition == "Excellent")
Inigoesdr is offline   Reply With Quote
Old 10-12-2007, 10:19 PM   PM User | #4
WA
Administrator


 
Join Date: Mar 2002
Posts: 2,596
Thanks: 2
Thanked 19 Times in 18 Posts
WA will become famous soon enough
Please read 1.5 on CF's rules page. 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.
__________________
- George
- JavaScript Kit- JavaScript tutorials and 400+ scripts!
- JavaScript Reference- JavaScript reference you can relate to.
WA is offline   Reply With Quote
Old 10-12-2007, 10:56 PM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by WA View Post
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.
Inigoesdr is offline   Reply With Quote
Old 10-12-2007, 11:14 PM   PM User | #6
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 10-13-2007, 12:37 AM   PM User | #7
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:34 AM.


Advertisement
Log in to turn off these ads.