Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,970 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,387 people online right now. Registration is fast and FREE... Join Now!




Code Help

 
Closed TopicStart new topic

Code Help

grimmben
3 Dec, 2007 - 09:21 PM
Post #1

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
This code is suppose to let me enter as many number of years for employee's also calculate and display the total number of employee
CODE
int main()
{
    //declare variables
    int years  = 0;
    int numberofemployees = 0;  //counter    
    //enter input data
    cout << "Enter the years employed: ";
    cin >> years;
while (numberofemployees >= 0)
    {
        //add numberofemployees to counter
        numberofemployees = years + numberofemployees;
        //get next numberofemployees
        cout << "Next numberofemployees (negative number to stop): ";
        cin >> numberofemployees;
    }   //end while

    //display vacation weeks
    if (years == 0)
        cout << "Vacation weeks: 0" << endl;
    else if (years <= 5)
        cout << "Vacation weeks: 1" << endl;
    else if (years <= 10)
        cout << "Vacation weeks: 2" << endl;
    else cout << "Vacation weeks: 3" << endl;
    //end ifs

    return 0;
}   //end of main function

User is offlineProfile CardPM
+Quote Post

harshakirans
RE: Code Help
3 Dec, 2007 - 11:01 PM
Post #2

D.I.C Head
Group Icon

Joined: 26 Apr, 2006
Posts: 122



Thanked: 3 times
Dream Kudos: 150
My Contributions
Can you post the objective, reason this code is written. Or the expected behavior you expect after running this code in better words.
User is offlineProfile CardPM
+Quote Post

grimmben
RE: Code Help
4 Dec, 2007 - 12:40 AM
Post #3

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
The program has to allow the user to enter the number of years for as many employee's as desired. Also add the appropriate code to calculate and display the total of employee's entered
QUOTE(harshakirans @ 4 Dec, 2007 - 12:01 AM) *

Can you post the objective, reason this code is written. Or the expected behavior you expect after running this code in better words.


User is offlineProfile CardPM
+Quote Post

Topher84
RE: Code Help
4 Dec, 2007 - 02:05 AM
Post #4

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232



Thanked: 1 times
Dream Kudos: 25
My Contributions
I"m not 100% sure what you are trying to do but you need a DO WHILE loop instead of a while loop ...

this lets you enters as many as you want, increments number of employees and displays the total number after each input

CODE

#include <iostream>

using namespace std;


int main()
{
    //declare variables
    int years  = 0;
    int numberofemployees = 0;  //counter    
  
    do
    {
        //enter input data
        cout << "Enter the years employed (negative value terminate program): ";
        cin >> years;

        //if user wants to quit and enters negative number
        if(years < 0)
        {
            cout << "Ending Program"; //display termination
            break;
        }
        

        numberofemployees++; //increment number of employees
  

        //display vacation weeks
        if (years == 0)
        {
            cout << "Vacation weeks: 0" << endl;
        }
        else if (years <= 5)
        {
            cout << "Vacation weeks: 1" << endl;
        }
        else if (years <= 10)
        {
            cout << "Vacation weeks: 2" << endl;
        }
        else
        {
            cout << "Vacation weeks: 3" << endl;
        }
        //display current total number of employees
        cout << "Total Number Of Employees: " << numberofemployees << endl;
       }while (numberofemployees >= 0);
    return 0;
}   //end of main function


This post has been edited by Topher84: 4 Dec, 2007 - 02:11 AM
User is offlineProfile CardPM
+Quote Post

grimmben
RE: Code Help
4 Dec, 2007 - 06:08 AM
Post #5

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
THANK'S A BUNCH YOU WERE A BIG HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

QUOTE(Topher84 @ 4 Dec, 2007 - 03:05 AM) *

I"m not 100% sure what you are trying to do but you need a DO WHILE loop instead of a while loop ...

this lets you enters as many as you want, increments number of employees and displays the total number after each input

CODE

#include <iostream>

using namespace std;


int main()
{
    //declare variables
    int years  = 0;
    int numberofemployees = 0;  //counter    
  
    do
    {
        //enter input data
        cout << "Enter the years employed (negative value terminate program): ";
        cin >> years;

        //if user wants to quit and enters negative number
        if(years < 0)
        {
            cout << "Ending Program"; //display termination
            break;
        }
        

        numberofemployees++; //increment number of employees
  

        //display vacation weeks
        if (years == 0)
        {
            cout << "Vacation weeks: 0" << endl;
        }
        else if (years <= 5)
        {
            cout << "Vacation weeks: 1" << endl;
        }
        else if (years <= 10)
        {
            cout << "Vacation weeks: 2" << endl;
        }
        else
        {
            cout << "Vacation weeks: 3" << endl;
        }
        //display current total number of employees
        cout << "Total Number Of Employees: " << numberofemployees << endl;
       }while (numberofemployees >= 0);
    return 0;
}   //end of main function



User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic
Time is now: 1/8/09 06:33PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month