5 Replies - 9351 Views - Last Post: 21 September 2006 - 05:08 PM Rate Topic: -----

#1 ldriscollodom  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 20-September 06

modulus operators

Posted 20 September 2006 - 06:51 AM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: modulus operators

#2 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

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

Was This Post Helpful? 0
  • +
  • -

#3 ldriscollodom  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 20-September 06

Re: modulus operators

Posted 20 September 2006 - 07:16 AM

thanks!

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.
Was This Post Helpful? 0
  • +
  • -

#4 Xing  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Re: modulus operators

Posted 20 September 2006 - 07:16 AM

The C++ Modulus Operator
Was This Post Helpful? 0
  • +
  • -

#5 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 175
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

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:
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.
Was This Post Helpful? 0
  • +
  • -

#6 Datalus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 235
  • Joined: 18-December 05

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.

This post has been edited by Datalus: 21 September 2006 - 05:10 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1