C++ to PDL conversion

Hi guys, for part of my second uni assignment I've had to write a fairly simple cpp program, which I have now finished, the problem is I also have to provide the codes equivalent in PDL which I am really struggling with. I'm aware this is a C++ forum but I'm really hoping somebody here with knowledge would be willing to confirm whether my attempt is on track or not.

Here is the CPP code:
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
35
36
37
 #include <iostream>
#include <cassert>
using namespace std;


double number; 
float variableShippingCost; 


void calculateVariableCost()
{
	if (number <= 100)
		variableShippingCost = 50 + (number*5.5);
	else if ((number > 100) && (number <= 500))
		variableShippingCost = 50 + (100 * 5.5) + ((number - 100)*4.0);
	else if (number > 500)
		variableShippingCost = 50 + (100 * 5.5) + (400 * 4.0) + ((number - 500)*2.5);
}

int main()
{

	cout << "Enter distance in miles: ";
	cin >> number;

	if (number <= 0)
		cout << "ERROR: The distance must be a positive value. \n \n";
	else
	{
		calculateVariableCost();
		cout << "The cost of the shipment over " << number << " miles is: " << (char)156 << variableShippingCost << "\n";
		
	}

system("PAUSE");
return 0;
}


Here is my PDL attempt:
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
global number, variableShipping Cost	//double/float

proc calculateVariableCost
	if number <= 100
	then
		variableShippingCost = 50 + (number*5.5)
	else
		if  ((number > 100) and (number <= 500))
		then 
			variableShippingCost = 50 + (100 * 5.5) + ((number - 100)*4.0)
	else
		if (number > 500)
		then
			variableShippingCost = 50 + (100 * 5.5) + (400 * 4.0) + ((number - 500)*2.5);
	endif
endproc

output(Enter distance in miles: )
input(number)

if (number <= 0)
	output(ERROR: The distance must be a positive value.)
else
	call calculateVariableCost
	output(The cost of the shipment over (number) miles is: (variableShippingCost))"
endif 


Thanks in advance for any help.
Last edited on
As this is a C++ forum, I'm not sure what kind of help you're expecting.

You could subscribe to the users mailing list: http://pdl.perl.org/?page=mailing-lists
Unfortunately they don't seem to have a forum despite paying to host the archives so the archaic mailing list is your only option.
Topic archived. No new replies allowed.