Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    Oct 2007
    Posts
    11
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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")

  • #4
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    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.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •