### Need Help with basic program

I am working on this project for school, I know it's sloppy, but can use a lot of help.

It closes after command is answered, how do I fix it?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586`` ``````// // Tyson Wieland Lab II // CIS-162-FD01 computer Programming: C++ // 8/28/13 // // 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 = // height = // package_size = // cost_per_inch // cost_per_pound // weight_cost // size_cost // package_cost // total_size // #include using namespace std; // cout and cin definitions. const double cost_per_inch= .25; //setting cost per inch constant const double cost_per_pound= 2.5; //setting cost per pound constant char girth; char height; char weight; char total_size=girth + height; //calculate the size char weight_cost=cost_per_pound * weight; //calculate the cost based on weight char size_cost=cost_per_inch * total_size; //calculate the cost based on size char cost_package=weight_cost + size_cost; //total cost of package char finish; int main() { int weight; cout<<"This program will help you calculate the cost of a package. Simple and easy!"<< endl; cout<<"What is the weight of your package?"; cin>>weight; //input weight if(weight < 0 || weight > 150) //prevents under and over sizing { cerr<<"UPS only allows packages up to 150 pounds. Sorry for this inconvience."<< endl; cerr<<"Type x and press enter to exit program"; cin>>finish; return EXIT_FAILURE; } cout<<"What is the girth of your package?"<< endl; cin>>girth; //input girth if(girth < 0 || girth > 1000000) { cerr<<"Unable to process"<< endl; cerr<<"Type x and press enter to exit program"; cin>>finish; return EXIT_FAILURE; } cout<<"What is the height of your package?"<< endl; cin>>height; //input height if(height < 0 || height > 1000000) { cerr<<"Unable to process"<< endl; cerr<<"Type x and press enter to exit program"; cin>>finish; return EXIT_FAILURE; } cout<<"\nYour final cost based on your input is" << cost_package << "dollars.\n"<< endl; //displays the cost to the user cout<<"Press x and press enter when finished"; cin>>finish; return(0); }``````
Last edited on
Whenever you return from the main function, the program is over and closes.

And after almost every cin you do this
`return EXIT_FAILURE;`
 ``1234567891011121314151617181920212223242526272829`` ``````// calculates the area of a rectangle #include #include // for EXIT_FAILURE int main() { /*char*/ double width ; // width is a number, not a character std::cout << "width? " ; std::cin >> width ; if( width < 0 ) { std::cerr << "width can't be negative\n" ; return EXIT_FAILURE ; } /*char*/ double height ; // height is a number, not a character std::cout << "height? " ; std::cin >> height ; if( height < 0 ) { std::cerr << "height can't be negative\n" ; return EXIT_FAILURE ; } // calculate the area *after* we know what the width and height are const double area = width * height ; std::cout << "area of the rectangle is " << area << '\n' ; }``````
Thanks!
Topic archived. No new replies allowed.