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;
}
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

Attachments
#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 ;

      int weeks_worked ,temp1;

      int days_worked ,temp2;

      int hrs_worked ;



      //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" ;





  
       //calculating the no of days ,weeks

	
	temp1 = (hours/hoursweek);        //converts the no of hours into weeks(only the integer part) 

        weeks_worked = hours % hoursweek ; //gives the reminder,when divided by weeks.
  
        temp2 = weeks_worked / hoursday ;   //gives the no of days(integer part)
	
	hrs_worked=weeks_worked % hoursday;        //reminder of hours left

  	
        
  
       
  
       
  
      //enter output items
  

      cout <<"Employee's name: "<<name<<endl;

      cout<<"working \t"<<temp1<<"weeks  "<<temp2<<"days  "<<hrs_worked<<"hours"<<endl;
     
  
     return 0;
}
This question has already been answered. Start a new discussion instead.