Please support our C++ advertiser: Programming Forums
![]() |
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:
my code:
c++ Syntax (Toggle Plain Text)
#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; }
Last edited by Ancient Dragon : Jan 11th, 2008 at 10:40 pm. Reason: add code tags
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,870
Reputation:
Rep Power: 40
Solved Threads: 1014
you forgot to include <string>
>> system ("pause") ;
Don't do that. Just use
>> system ("pause") ;
Don't do that. Just use
cin.get() •
•
Join Date: Sep 2007
Location: Ukraine, Kyiv
Posts: 114
Reputation:
Rep Power: 0
Solved Threads: 11
C++ Syntax (Toggle Plain Text)
cout <<"Employee's name: "<<name:<< worked <<hours % hoursweek<< " \n\n" ;
C++ Syntax (Toggle Plain Text)
cout <<"Employee's name: "<<name<<"Worked: "<< worked <<"Hours: "<<hours % hoursweek<< " \n\n" ;
Last edited by zhelih : Jan 12th, 2008 at 12:44 pm.
An Apple a Day keeps a Doctor away!
•
•
Join Date: Nov 2007
Posts: 52
Reputation:
Rep Power: 2
Solved Threads: 3
you cannot declare an int with spaces
the identifier is illegal in c++ it shouldn't contain spaces
int hours % hoursweek;
the identifier is illegal in c++ it shouldn't contain spaces
![]() |
Similar Threads
Other Threads in the C++ Forum
- help plz (C++)
Other Threads in the C++ Forum
- Previous Thread: Restarting Application
- Next Thread: problem with g++ compiler
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode