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

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




employee's hours worked

 
Reply to this topicStart new topic

employee's hours worked

yarita
11 Jan, 2008 - 02:22 PM
Post #1

New D.I.C Head
*

Joined: 11 Jan, 2008
Posts: 1

I am just beginning in a C++ class and I am having a hard time setting up the code for using a modulus operator. The problem assigned has user input as name and hours worked. The program is to output the name, weeks worked, days worked, and hours worked based on the hours worked input. I keep getting errors on my code on the last part, which is the output. Can someone help me out on this? I'm very confused right now!


my code:

CODE
#include <iostream>
using namespace std;

int main ()
{
    
    // declares cnstants and variables
      
    string name; //name is a variable of type string
    const int hoursweeek = 40;
    const int hoursday = 8;
    int hours = 0;
    int weeks_worked = 0;
    int days_worked  = 0;
    int hrs_worked = 0;
    
    //enter input items  
    cout <<"Enter employee's name: \n\n";
    cin >>name;
    getline (cin,name);
    
    cout <<"\n\n";
        
    cout <<"Enter number of hours worked: \n\n";
    cin >>hours;
    cout <<"\n\n";
    
    //calculate weeks, days, and hours worked
    weeks_worked = hours / hoursweek
    
    
    //enter output items  
    cout <<"<<name<<" worked "<<_weeks, _days, and _hours<<" \n\n";
            
            
    system ("pause");
    return 0;
}


*mod edit - please remember to code.gif
User is offlineProfile CardPM
+Quote Post

GWatt
RE: Employee's Hours Worked
11 Jan, 2008 - 03:27 PM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,199



Thanked: 20 times
Dream Kudos: 450
My Contributions
This probably isn't causing you any problems, but you don't need to get the employee name twice. Just use getline(cin, name);

Anyway, the modulus operator gives you the remainder. So 16 % 9 will give you 7.

You did weeks worked fine, and then you do hours % hoursweek and assign that to an int. Do the same thing for the leftoever hours from that.
User is online!Profile CardPM
+Quote Post

carltech
RE: Employee's Hours Worked
12 Jan, 2008 - 05:53 PM
Post #3

New D.I.C Head
Group Icon

Joined: 19 Oct, 2007
Posts: 42


Dream Kudos: 25
My Contributions
QUOTE
cout <<"<<name

the " at the beginning after << shouldn't be there. Also instead of
QUOTE
"\n\n"
you can say
<< endl << endl;
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 04:19AM

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