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 understand how to break it down in calculation; but our instructor wants us to a modulus operator. I am unsure of how to do this. Any hints?
modulus operators
Page 1 of 15 Replies - 9351 Views - Last Post: 21 September 2006 - 05:08 PM
Replies To: modulus operators
#2
Re: modulus operators
Posted 20 September 2006 - 07:04 AM
Show us ure code. Dont worry if u go wrong. We'll help u out. It'll help u learn better
This post has been edited by Louisda16th: 20 September 2006 - 07:06 AM
#3
Re: modulus operators
Posted 20 September 2006 - 07:16 AM
thanks!
Here's what i have so far:
***
This is where I'm not sure how to set up the mod to get to daysWorked.
Here's what i have so far:
int main()
{
//declare constants and variables
string name = "";
const int HOURSWEEK = 40;
const int HOURSDAY = 8;
int hours = 0;
int hrsWorked = 0;
int daysWorked = 0;
int weeksWorked = 0;
//get user's input
cout << "Enter employee's name: ";
cin >> name;
cout << "Enter employee's hours worked: ";
cin >> hours;
//calculate weeks, days and hours worked
weeksWorked = hours / HOURSWEEK
***
This is where I'm not sure how to set up the mod to get to daysWorked.
#5
Re: modulus operators
Posted 21 September 2006 - 07:19 AM
Maybe your instructor want's your output in this manner.
x Weeks Worked + 3 Days.
(that is, if the number of hours doesn't exactly correspond to an exact value of weeks_worked).
In that case you can use something like this:
This will give you the value (remainder) of the number of days left which doesn't complete a week's worth of work.
x Weeks Worked + 3 Days.
(that is, if the number of hours doesn't exactly correspond to an exact value of weeks_worked).
In that case you can use something like this:
days_worked = weeks_worked % 7;
This will give you the value (remainder) of the number of days left which doesn't complete a week's worth of work.
#6
Re: modulus operators
Posted 21 September 2006 - 05:08 PM
Modulus( A, B ) or A % B = A - floor( A / B ) * B
floor( ...) means always round down to the nearest integer.
floor( ...) means always round down to the nearest integer.
This post has been edited by Datalus: 21 September 2006 - 05:10 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|