0

i am trying to calculate hours it takes to complete each week depending on if user asks for total or average, this is not the full code but the part shown is one that should do the calculation. I am trying to first calculate for total.

float calc_hours(int hours[], int weeks, char output)
{
int total = 0;
    {
    for (i = 0 ; i < weeks ; i++)
        {
            total += hours;
        }
  } 
    
}

1 Answer 1

1

Simple problem. The code is trying to use i as the counter in the for loop, but i hasn't been declared. Try this instead. Note the addition of the type declaration keyword "int".

for (int i = 0 ; i < weeks ; i++)

I'm guessing that at some point, you'll want to use a return statement to return the calculated value.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks for your help! I just joined and I'm already loving it here!
    – Gold Isaac
    Commented Apr 4, 2023 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .