Hello, ok, so here is my problem/issue I'm having with this code. This is a program that asks a user for days worked, pay rate and hours worked per day.
I'm supposed to create a pointer to a dynamically allocated array of the size equal to days worked.
I sorted coded everything before figuring out the pointer..I got stuck figuring out the math portion to get a gross total(1st issue)
Now, I am sort of working backwards and trying to figure how/where to build the pointer to the dynamically allocated array. (you will notice a big chunk of commented out code, this was my rough draft prior to adding in the pointer. I wanted to just get the basics in first then piece everything out.)
What I need help with.
1. building the pointer to a dynamically allocated array of the size equal to days worked
2. help with the math formula to calculate the gross pay
Here is what I have, if anyone could give me hand with I would appreciate it so MUCH!
hi,
here are your answers:
first, hours is not initialized and you are allocating memory to daysworked from uninitialized variable (default is 0)
second, hours is a single int, not an array to ints but daysworked is a pointer, so according to its size, it can be used like arrays
so, you should do daysworked[hours-1] (it starts from 0)