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:

#include <iostream>
using namespace std;

int main ()
{
    
    // declares constants and variables 
       
    string name ; //name is a variable of type string
    const int hoursweek = 40;
    const int hoursday = 8;
    int hours = 0;
    int weeks_worked = 0;
    int days_worked  = 0;
    int hrs_worked = 0;
    int hours % hoursweek = 0;
    
    
    //enter input items  
    cout <<"Enter employee's name: \n\n";
    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 ; 
    days_worked  = hours % hoursweek ;
    hrs_worked = hours % hoursweek ;
    
     
    //enter output items  
    cout <<"Employee's name: "<<name:<< worked <<hours % hoursweek<< " \n\n" ;
            
            
    system ("pause") ;
    return 0;
}

you forgot to include <string>

>> system ("pause") ;
Don't do that. Just use cin.get()

cout <<"Employee's name: "<<name:<< worked <<hours % hoursweek<< " \n\n" ;

Why do you put two points after name?

cout <<"Employee's name: "<<name<<"Worked: "<< worked <<"Hours: "<<hours % hoursweek<< " \n\n" ;

you cannot declare an int with spaces

int hours % hoursweek;

the identifier is illegal in c++ it shouldn't contain spaces

sending the code,which i suppose u were working upon

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.