Why is this returning 0 and not 30

Hi please explain why this is not returning 30 thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include<iostream>

signed long Perimeter (unsigned short int, unsigned short int);

int main()
{


unsigned short int theLength, theWidth;
theLength = 5;
theWidth = 10;

std::cout << "The perimeter is : "<<Perimeter(theLength,theWidth)<<std::endl;

}

signed long Perimeter(unsigned short int, unsigned short int)
{
unsigned short int length;
unsigned short int width;

return (length * 2) + (width * 2);
}
"q1_q2ch4.cpp" 23L, 409C                                      23,1          All
Last edited on
Your function Perimeter. It does nothing with the values you pass it. Doesn't even have names for them. Instead, you create two new variables and work with them.


1
2
3
4
signed long Perimeter(unsigned short int value_one, unsigned short int value_two)
{
  return (value_one * 2) + (value_two * 2);
}

It does not matter but why is the function Perimeter a signed long? It won't ever return a negative value...
Do you want a hand hold or a hint?
Here's a hint first...
Inside of your function the Length and width have no values to them. You're multiplying something by something.
Topic archived. No new replies allowed.