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?

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
//	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 <iostream>
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;
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
// calculates the area of a rectangle

#include <iostream>
#include <cstdlib> // 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.