Need some newb pointers

This is a discussion on Need some newb pointers within the C++ Programming forums, part of the General Programming Boards category; I have tried to code this project but I am having trouble, I think I am close but no cigar. ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    4

    Need some newb pointers

    I have tried to code this project but I am having trouble, I think I am close but no cigar. No this is not homework! I finished that and chose to attempt this one from my book on my own. Can anyone show me my issues and explain why I am not code compliant? Any help is greatly appreciated thank you in advance for advise:

    Written directives from my book were as follows:

    Design a program that computes pay for employees. Allow a user to continuously input employees’ names until an appropriate sentinel value is entered. Also input each employee’s hourly wage and hours worked. Compute each employee’s gross pay (hours times rate), withholding tax percentage (based on the accompanying table), withholding tax amount, and net pay (gross pay minus withholding tax). Display all the results for each employee. After the last employee has been entered, display the sum of all the hours worked, the total gross payroll, the total withholding for all employees, and the total net payroll.


    Weekly Gross Pay Withholding Percent

    (%)
    0.00 – 200.00 10
    200.01 – 350.00 14
    350.01 – 500.00 18
    500.01 – up 0 22



    Code:
    //Program: Payroll Report
    //PayrollReport.cpp 
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <string>
    #include <cmath>
    using namespace std;
    string empName;
    int *salary = 0;
    int hrsWorked = 0;
    int x = 0;
    int grossPay = 0;
    int withTax = 0;
    int netPay = 0;
    int totalGrossPay = 0;
    int totalHrsWorked = 0;
    int totalWithTax = 0;
    int totalNetPay = 0;
    string QUIT = "zzzz";
    const int SIZE = 4;
    double WITH_RATE[SIZE] = {0.10, 0.14, 0.18, 0.22};
    double WITH_RANGE[SIZE] = {0, 200.01, 350.01, 500.01};
    int main()
    {
     cout << "Enter an employee name or ", QUIT, " zzzz ";
     cin >> empName;
     
            while (empName != QUIT)
         {
          cout << "enter", empName, "'s hourly wage and hours worked";
                cin >> *salary, hrsWorked;
          grossPay = hrsWorked * *salary;
          totalHrsWorked = totalHrsWorked + hrsWorked;
          totalGrossPay = totalGrossPay + grossPay;
          x = SIZE -1;
               }
          while (grossPay < WITH_RANGE[x]){
                    x = x -1;
               }            
        withTax = (grossPay * WITH_RATE[x]);
                endwhile
           totalWithTax = totalWithTax + withTax;
        netPay = grossPay - withTax;
        totalNetPay = totalNetPay + netPay;
        cout << empName, grossPay, WITH_RATE[x] * 100, withTax, netPay;
        cout << "Enter an employee name or ", QUIT, " zzzz ";
        cin >> empName;
               }
               endwhile
                    cout << totalHrsWorked, totalGrossPay, totalWithTax, totalNetPay;
                    return 0; 
    system("PAUSE");
        
    }

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    Your comments are appreciated!

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    13
    endwhile is not declared or initialized. Maybe you meant that as a comment to show where the while statements end but it needs // in front if that is the case or just delete them entirely. You also have an extra } before the second endwhile. Are you trying to use pointers? Because you declared int *salary to be a pointer but you never assign it another variables address. I would suggest not making it a pointer b/c it doesn't have to be but if you want practice then check out this tutorial on pointers first to see how to set them up. Here's the link

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    Quote Originally Posted by Fandango21 View Post
    endwhile is not declared or initialized. Maybe you meant that as a comment to show where the while statements end but it needs // in front if that is the case or just delete them entirely. You also have an extra } before the second endwhile. Are you trying to use pointers? Because you declared int *salary to be a pointer but you never assign it another variables address. I would suggest not making it a pointer b/c it doesn't have to be but if you want practice then check out this tutorial on pointers first to see how to set them up. Here's the link
    Thank you for your response.......... I was begining to think the post was a wash due to the overwhelming snobi-ness that seems to seeth under the brilliant crowds feet. Yours is a welcome pointer. I tip my hat to you sir!

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Code:
    cout << "Enter an employee name or ", QUIT, " zzzz ";
    ...
    cout << "enter", empName, "'s hourly wage and hours worked";
    cin >> *salary, hrsWorked;
    ...
    cout << empName, grossPay, WITH_RATE[x] * 100, withTax, netPay;
    cout << "Enter an employee name or ", QUIT, " zzzz ";
    ...
    cout << totalHrsWorked, totalGrossPay, totalWithTax, totalNetPay;
    What's with all those commas in your I/O? I'm certain that you don't want to be doing that. Do you mean to use <</>>?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,697
    Why all the global variables? You only have one function, put them inside the function. Using global variables is a bad practice that leads to hard to maintain, hard to troubleshoot programs.

    Jim

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    13
    Here's your code I modified that you can look at and kind of see with better indentations,working while loop and such. Let me know if you have any questions about the changes.

    Code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    int main() {
    
    string empName;
    int x = 0;
    double salary, hrsWorked, grossPay, withTax, netPay, totalGrossPay = 0, totalHrsWorked = 0, totalWithTax = 0, totalNetPay = 0;
    string QUIT = "zzzz";
    const int SIZE = 4;
    double WITH_RATE[SIZE] = {0.10, 0.14, 0.18, 0.22};
    double WITH_RANGE[SIZE] = {0, 200.01, 350.01, 500.01};
    	
        cout << "Enter an employee name or " << QUIT << " to quit: ";
        cin >> empName;
      
        while (empName != QUIT) {
    	cout << "Enter " << empName << "'s hourly wage: ";
    	cin >> salary;
    	cout << "Enter " << empName << "'s hours worked: ";
    	cin >> hrsWorked;
    
    	grossPay = hrsWorked * salary;
            totalHrsWorked = totalHrsWorked + hrsWorked;
    	totalGrossPay = totalGrossPay + grossPay;
    	x = SIZE -1;
    	
    	while (grossPay < WITH_RANGE[x]) {
    		x = x -1;
    	}      
    
            withTax = (grossPay * WITH_RATE[x]);
            totalWithTax = totalWithTax + withTax;
            netPay = grossPay - withTax;
            totalNetPay = totalNetPay + netPay;
    
            cout << "Employee: " << empName << endl;
            cout << "Gross Pay: " << grossPay << endl;
            cout << "With Rate: " << WITH_RATE[x] * 100 << endl;
            cout << "With Tax: " << withTax << endl;
            cout << "Net Pay: " << netPay << endl;
            cout << endl;
    
            cout << "Enter an employee name or " << QUIT << " to quit: ";
            cin >> empName;
    
        }
              
        cout << "Total Hours: " << totalHrsWorked << " " <<
    	    "Total Gross Pay: " << totalGrossPay << " " <<
    	    "Total With Tax: " << totalWithTax << " " << 
    	    "Total Net Pay: " << totalNetPay << endl;
        cout << endl;
                   
    system("PAUSE");
    return 0; 
         
    }

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    4

    Thanks a million sir!!

    Fandango you are an impressive code writer! You did in a few moments what would have been a lifetime of work for me. I am new to this and inspired by your helpful insights...... I shall study your work over the next few weeks and try to aspire to your inspirational work! I tip my hat and if we should meet I would like to buy you a nice steak and as much alcohol you could handle at the nearest gentlemans club!!

    Like I said I am new to this but fascinated by the sheer power programmers weild with their very fingertips. Bravo sir I owe you sir! I would like to seek your help in the future and I am sure you are a very busy man indeed. I am assuming you do this for a living.... Best Wishes and many thanks for answering many of my coding questions as an engineer once said to me it's the devil in the details! You ROCK!!
    Last edited by dawallace; 11-24-2011 at 01:13 AM.

  9. #9
    Registered User
    Join Date
    Feb 2011
    Posts
    13
    No problem. I'm still learning C++ myself, and coding in general, but glad I could help.

  10. #10
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    I tip my hat and if we should meet I would like to buy you a nice steak and as much alcohol you could handle at the nearest gentlemans club!!
    I really should post more ;->
    Last edited by rogster001; 11-24-2011 at 05:36 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    You both need to improve your indentation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    I was begining to think the post was a wash due to the overwhelming snobi-ness that seems to seeth under the brilliant crowds feet.
    Just a note, this is not the way to ingratiate yourself to people who are volunteering to help you and others, and do so every day.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The newb has a newb request
    By Pancakes in forum C Programming
    Replies: 15
    Last Post: 05-27-2011, 08:04 PM
  2. help for a newb?
    By nonshatter in forum C Programming
    Replies: 1
    Last Post: 11-26-2008, 10:12 AM
  3. newb help
    By joker_tony in forum C Programming
    Replies: 5
    Last Post: 09-21-2008, 08:49 PM
  4. Newb Needs Help!!!!!!!!!!!!!!!!!
    By majornewb in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2004, 08:11 AM
  5. newb q
    By Klinerr1 in forum C++ Programming
    Replies: 4
    Last Post: 07-06-2002, 11:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21