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.
// 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>
usingnamespace 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;
constdouble cost_per_inch= .25; //setting cost per inch constant
constdouble cost_per_pound= 2.5; //setting cost per pound constant
constdouble package_size=girth + height; //calculate the size
constdouble weight_cost=cost_per_pound * weight; //calculate the cost based on weight
constdouble size_cost=cost_per_inch * package_size; //calculate the cost based on size
constdouble 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
}
}
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.