Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,375 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,151 people online right now. Registration is fast and FREE... Join Now!




modulus operators

 
Reply to this topicStart new topic

modulus operators

ldriscollodom
post 20 Sep, 2006 - 05:51 AM
Post #1


New D.I.C Head

*
Joined: 20 Sep, 2006
Posts: 3



Thanked 1 times
My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

Louisda16th
post 20 Sep, 2006 - 06:04 AM
Post #2


 

Group Icon
Joined: 3 Aug, 2006
Posts: 1,790



Thanked 1 times

Dream Kudos: 755
My Contributions


Show us ure code. Dont worry if u go wrong. We'll help u out. It'll help u learn better smile.gif

This post has been edited by Louisda16th: 20 Sep, 2006 - 06:06 AM
User is offlineProfile CardPM

Go to the top of the page

ldriscollodom
post 20 Sep, 2006 - 06:16 AM
Post #3


New D.I.C Head

*
Joined: 20 Sep, 2006
Posts: 3



Thanked 1 times
My Contributions


thanks!

Here's what i have so far:
CODE

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.
User is offlineProfile CardPM

Go to the top of the page

Xing
post 20 Sep, 2006 - 06:16 AM
Post #4


D.I.C Addict

Group Icon
Joined: 22 Jul, 2006
Posts: 723



Thanked 2 times

Dream Kudos: 1575
My Contributions


The C++ Modulus Operator
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 21 Sep, 2006 - 06:19 AM
Post #5


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

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


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:
CODE

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.
User is offlineProfile CardPM

Go to the top of the page

Datalus
post 21 Sep, 2006 - 04:08 PM
Post #6


D.I.C Head

Group Icon
Joined: 18 Dec, 2005
Posts: 235



Dream Kudos: 35
My Contributions


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 Sep, 2006 - 04:10 PM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 06:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month