//
// 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>
usingnamespace std; // cout and cin definitions.
constdouble cost_per_inch= .25; //setting cost per inch constant
constdouble 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);
}
// 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
constdouble area = width * height ;
std::cout << "area of the rectangle is " << area << '\n' ;
}