Hello, any idea why the program closes before allowing me to input? Doesn't let me input a thing, not complete yet, just wanted to figure out before moving on.
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
int weight, distance;
float a, x, y, z;
a = 1.10;
x = 2.20;
y = 3.70;
z = 4.80;
cout << "Freight Shipping Rates\n";
cout << "--------------------------------------------------------\n";
cout << "5 pounds or less"; cout.width(39); cout << "$1.10\n";
cout << "Over 5 pounds but not more than 15 "; cout.width(20); cout << "$2.20\n";
cout << "over 15 pounds but not more than 30"; cout.width(20); cout << "$3.70\n";
cout << "over 30 pounds but not more than 50"; cout.width(20); cout << "$4.80\n";
cout << "-----------------------------------------------------------------\n";
cout << "NOTICE: We do not ship packages over 50 pounds\n";
cout << "We do not ship less than 10 miles or more than 3,000 miles\n";
cout << "Please enter the weight in pounds of your package";
cin >> weight;
cout << "Please enter the distance in miles of your shipment";
cin >> distance;
cout << if (weight weight <= 5) weight *= a;
elseif (weight > 5 && weight <= 15) weight *= x;
elseif (weight > 15 && weight <= 30) weight *= y;
elseif (weight > 30 && weight < 50) weight *= z;
system("PAUSE");
return 0;
}
#include <iomanip>
#include <iostream>
#include <limits>
void waitForEnter();
int main()
{
std::cout << "Freight Shipping Rates\n""--------------------------------------------------------\n""5 pounds or less" << std::setw(39) << "$1.10\n""Over 5 pounds but not more than 15 " << std::setw(20) << "$2.20\n""over 15 pounds but not more than 30" << std::setw(20) << "$3.70\n""over 30 pounds but not more than 50" << std::setw(20) << "$4.80\n""-----------------------------------------------------------------\n""NOTICE: We do not ship packages over 50 pounds\n""We do not ship less than 10 miles or more than 3,000 miles\n";
std::cout << "Please enter the weight in pounds of your package: ";
int weight {0};
std::cin >> weight;
std::cin.ignore(1);
std::cout << "Please enter the distance in miles of your shipment: ";
int distance {0}; // std::distance() declared in <iterator>
std::cin >> distance;
std::cin.ignore(1);
double a, x, y, z;
a = 1.10;
x = 2.20;
y = 3.70;
z = 4.80;
if (weight <= 5) { weight *= a; }
elseif (weight > 5 && weight <= 15) { weight *= x; }
elseif (weight > 15 && weight <= 30) { weight *= y; }
elseif (weight > 30 && weight < 50) { weight *= z; }
// else... <-- what if weight > 50?
std::cout << "weight: " << weight << '\n';
waitForEnter();
return 0;
}
void waitForEnter()
{
std::cout << "\nPress ENTER to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}