Always returning 1 instead of deesired value

Please why is it always returning 1 instead of the perimiter value I used the example in the book and only had to change it slightly to do the question. How can I make it return the correct value of the math.

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
26
27
28
29
30
31
32
33
34
#include <iostream>

using namespace std;

typedef unsigned long int ULONG;

typedef unsigned short int UINT;

ULONG findPerimeter(UINT length, UINT width);

int main(){

UINT lengthSize;
UINT widthSize;
ULONG perimeterSize;

cout << "Enter the length.\n";
cin >> lengthSize;
cout << "Enter the width.\n";
cin >> widthSize;

perimiterSize = findPerimeter(lengthSize,widthSize);

cout << "The answer is " << perimeterSize << endl;

}

ULONG findPerimeter (UINT 1, UINT w)
{

return 1 * 2 + w * 2;

}
                                                                                                                                                                                                                                                             









Last edited on
Your posted code doesn't compile. (You've also got some very long lines of blanks.)

(1) perimiterSize - spelling!!!

(2)
1
2
3
4
ULONG findPerimeter (UINT 1, UINT w)
{

return 1 * 2 + w * 2;

1 isn't a variable (two occurrences). Change it to L (lower case is too hard to distinguish from 1).

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

typedef unsigned long int ULONG;
typedef unsigned short int UINT;

ULONG findPerimeter(UINT length, UINT width);

int main()
{
   UINT lengthSize, widthSize;
   ULONG perimeterSize;

   cout << "Enter the length: ";   cin >> lengthSize;
   cout << "Enter the width:  ";   cin >> widthSize;

   perimeterSize = findPerimeter(lengthSize,widthSize);
   cout << "The answer is " << perimeterSize << endl;
}

ULONG findPerimeter (UINT L, UINT w)
{
   return L * 2 + w * 2;
}


Enter the length: 2
Enter the width:  3
The answer is 10
Last edited on
Topic archived. No new replies allowed.