English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm currently trying to write a program. I'm new at programming and horrible at math. It is due tomorrow. I need to display the weeks, days, and hours a person worked based on the hours the person worked that month, which could be any number. A week is 40 hours, a day is 8 hours, and however many hours are left. I already wrote up my code and ran the compiler. However, the calculations are way off. I just need to know how to calculate the weeks, days, and hours.
I included the variables I declared and the calculations. Thank you.

//declare variables
int hoursWorked = 0;
int hoursPerWeek = 40;
int hoursPerDay = 8;
int weeks = 0;
int days = 0;
int hours = 0;

//calculate weeks, days, and hours
weeks = (hoursWorked - hoursPerWeek)/ ;
days = weeks - hoursPerDay;
hours = days;

2007-02-12 16:20:53 · 5 answers · asked by Christi 4 in Computers & Internet Programming & Design

I'm writing this in C++ using Dev-C++

2007-02-12 16:34:29 · update #1

5 answers

Using your starting variables, you actually calculate backwards. So, you begin by getting the integer portion of the hours worked divided by the hours in a week:

hours = hoursWorked;

weeks = (int) hours / hoursPerWeek;

Next, you subtract that integer value from the hoursWorked:

hours -= weeks * hoursPerWeek;

Now, you repeat this with the proper number of hoursPerDay:

days = (int) hours / hoursPerDay;

And subtract that from the number of hours worked:

hours -= days * hoursPerDay;

And viola, you have the number of weeks, days and hours worked.

Let's suppose you have someone who worked 317 hours:

hours = 317;

weeks = 317 / 40 = 7.925 // int = 7

hours -= 7 * 40 = 37 // 7 * 40 = 280

days = 37 / 8 = 4.625 // int = 4

hours -= 4 * 8 = 5 // 4 * 8 = 32

So we have that if you worked for 317 hours, you worked 7 weeks, 4 days and 5 hours.

2007-02-12 17:23:01 · answer #1 · answered by Anonymous · 0 0

weeks=hoursWorked/hoursPerWeek;
days=hoursWorked/hoursPerDay;
hours=hoursworked;

Actually i couldn'd understand your queston completely. Any how i have written the mathematical part of your program. I thing it is correct.

All the best to complete your program. No harm whether you using C++ or Java. You can use the above simple statements. Let me know whether it is correct or not Bcoz i'm also learning programming.

2007-02-12 16:30:20 · answer #2 · answered by Anonymous · 0 0

If you have depression you need to see a doctor and get a referral to a psychologist who can help you. So your sister in law set you up with a family friend and it didn't work out. You should have said we aren't fighting I was ending the relationship. As it is family friend your sister in law is interested but you have to say it didn't work out as he does alcohol and drugs and its not the sort of person you want to be with. You were upset and felt misunderstood so called her *****. It's never nice name calling particularly if it is someone in the family. You apologised and now you need to move on. I would tell your family you apologised and felt misunderstood about how you ended the relationship and you understand name calling isn't nice thing to do.

2016-03-29 04:24:13 · answer #3 · answered by Anonymous · 0 0

Would you like me to help you? I'm dj_mikkie_v@yahoo.com

2007-02-12 16:28:06 · answer #4 · answered by Kaybee 2 · 0 0

you need to set the multiplyers.

2007-02-12 16:27:38 · answer #5 · answered by gas_indycar 5 · 0 0

fedest.com, questions and answers