Counter problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SnugsCafe
    New Member
    • Oct 2006
    • 3

    #1

    Counter problem

    I need this program to display the number of vacation weeks based on the number of years an employee has been with a company. It needs to allow me to enter the number of years for as many employees as I like. I would also like it to calculate and display the total number of employees entered.
    How do I make code for a counter? And how do I get the error message to work(b/c it's not working as far as I know)? I would really appreciate any advice or help.

    #include <iostream>
    using namespace std;

    int main()
    {
    int years = 0;
    int counter = 1;
    int employees = 0;

    cout << "Enter the years employed: ";
    cin >> years;

    while (years != -3)
    {
    {if (years == 0)
    cout << "Vacation weeks: 0" << endl;
    else if (years > 0 && years <= 5)
    cout << "Vacation weeks: 1" << endl;
    else if (years > 5 && years <= 10)
    cout << "Vacation weeks: 2" << endl;
    else if (years > 10)
    cout << "Vacation weeks: 3" << endl;
    else cout << "Invalid years" << endl;
    }

    cout << "Enter the years employed: ";
    cin >> years;

    }

    return 0;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    a. initialise you counter variable to 0
    b. at the start of the loop increment the counter

    counter++;

    c. After the loop has finished output the value of counter.

    Comment

    • SnugsCafe
      New Member
      • Oct 2006
      • 3

      #3
      Thank you! :)

      Comment

      Working...