Code Cleaning

Looking to figure out what is wrong with my code, running on a simple command prompt through microsoft c++. It is a rewritten code that worked before changing it to functions. It is for a class so format must stay the same, but now when it runs it goes blank so looking for advise. I realized it is missing things and incomplete, more so looking at getting it to start up.

Here is the current 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//	Calculates the cost for delivery of packages based on weight, package size, girth, and height.
//
//	Variables Below
//	cost = the final cost of the delivery of a package (output)
//	weight = the weight of the package (input) min=0 max=150 (Looked it up!)
//	girth = the girth of the package (input)
//	height = the height of the package (input)
//	package_size = the girth plus the height
//	cost_per_inch= constant for the cost based on size
//	cost_per_pound= constant for the cost based on the weight
//	weight_cost= the cost based on cost_per_pound * weight
//	size_cost= the cost based on cost_per_inch * package_size
//	package_cost= the total cost of size_cost + weight_cost
//


#include <iostream>
#include <iomanip>

using namespace std;										// cout and cin definitions.
void description();											//setting as void
void process();												//setting as void
void calculated();											//setting as void

double weight=45.0;
double girth=63.2;
double height=13.8;

const double cost_per_inch= .25;							//setting cost per inch constant
const double cost_per_pound= 2.5;							//setting cost per pound constant
const double package_size=girth + height;					//calculate the size
const double weight_cost=cost_per_pound * weight;			//calculate the cost based on weight	
const double size_cost=cost_per_inch * package_size;		//calculate the cost based on size	
const double cost_package=weight_cost + size_cost;			//total cost of package

int main()
{
	void description();
	void process();
	void calculated();
	return(0);
}
void description()
{
	cout<<"The weight is: "<<weight<<endl;
	cout<<"The girth is: "<<girth<<endl;
	cout<<"The height is: "<<height<<endl;

}

void process()
{


	setprecision(2);



}

void output()
{
	cout<<"The total size girth plus height: "<<package_size<<endl;
	cout<<"The cost per inch is: $.25"<<endl;
	cout<<"The cost per pound is: $2.50"<<endl;				
	cout<<"The cost based on size is: $"<<size_cost<<endl;
	cout<<"The cost based on weight is: $"<<weight_cost<<endl;
	cout<<"\nThe final cost is $" <<cost_package<< endl;  //displays the cost to the user
}
}
Where is void calculated()?
1
2
3
4
void process()
{
    cout << setprecision(2);
}

Look at the example
http://www.cplusplus.com/reference/iomanip/setprecision/
Last edited on
Your main() does nothing
ne555 is correct.

Your calling your functions in main as prototypes with the 'void' in front of it.

They should be called thusly:

1
2
3
4
5
6
7
int main()
{
	description();
	process();
	output();
	return(0);
}


Furthermore you have an additional closing curly bracket at the final line of your program and I believe you "void calculated();" you have created a prototype for function that does not exist. I think it should be:
void output(); above your main loop.

Finally look at what maeriden has said about how to use setprecision, it should be set inline with the text you're trying to output.
K thanks, I knew I mixed something up. It was a different code that got mixed in with this one.
Topic archived. No new replies allowed.