Thread: various wages calculation

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    Unhappy various wages calculation

    Hi guys.Im really2 new in c++ programming i hope u guys can help me.here`s the question,calculate the wages for the employee`s and display various wages information.the program should accept an employee number,base pay rate per hour,and the number of hours worked.here`s my attempt

    Code:
    #include <iostream.h>
    
     int empNum;     //employee`s number
     int payRate;    //base pay rate per hour
     int hours;      //hours worked
     float overtime; //amount paid with overtime hours
     float netWage;  //net wages of employee`s
     float aveWage;  //average wages paid to the employee`s
     float miniWage; //minimun wages paid to the employee`s
     float totWage;  //total wages paid to the employee`s
    int main()
    {
    
        cout << "Enter employee`s number:";
        cin >> empNum
    
        do
    
        {
          cout << "Enter hours worked:";
          cin >> hours;
    
          cout << "Enter base pay rate per hour:";
          cin >> payRate;
    
        if (hours > 40){
         overtime = payRate * 1.5;
      }
      else
        netWage = hours + payRate;
        totWage = hours + payRate;
        aveWage = totWage/2;
        miniWage = smallest netWage;
    
    
      }while (empNum <= 2);
    
      return 0;
    
     }

    seriously i`m new in programming,thanks for any help.
    Last edited by Salem; 12-01-2012 at 12:06 AM. Reason: tag fix

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
      else
        netWage = hours + payRate;
        totWage = hours + payRate;
        aveWage = totWage/2;
        miniWage = smallest netWage;
    Despite your indentation, it's only netWage which is part of the else statement.

    If you want all 4 lines to be part of the else, you need braces.
    Code:
      else {
        netWage = hours + payRate;
        totWage = hours + payRate;
        aveWage = totWage/2;
        miniWage = smallest netWage;
      }
    Until you're absolutely confident in knowing when braces are optional, you don't lose anything by using braces all the time.
    Using them all the time gives you one less thing to worry about.

    > miniWage = smallest netWage;
    This won't work - what is smallest?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calculation always gives 0
    By Emma K in forum C Programming
    Replies: 18
    Last Post: 11-24-2010, 06:00 PM
  2. Tracking C Programmer Wages and Jobs
    By jk33 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-27-2008, 11:14 PM
  3. wages code
    By dtaylor01 in forum C++ Programming
    Replies: 5
    Last Post: 10-15-2008, 11:46 AM
  4. Wages Calculation Program
    By DrKillPatient in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2005, 07:06 AM
  5. career and wages
    By watshamacalit in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-12-2003, 09:42 PM

Tags for this Thread