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
|
#include <iostream>
#include <iomanip> //THis is to format the outputs.
#include <cstdlib> //This is for generating random zip codes.
using namespace std;
int main()
{
//Variables for string input
string name, street, city, state;
// Variables for the zip code math.
int zip, check,
ones,
tens, tensA,
hund, hundA,
thou, thouA,
tenK, tenKA,
sum;
//Variables for Postage rates
int package;
double weight, postage;
//These are the shipping rates
const double LETTER = 0.49,
LETTERplus = 0.22,
ENVELOPE = 0.98,
ENVELOPEplus = 0.22,
PARCEL = 2.54,
PARCELplus = 0.20;
//This section informs the user of the program's intent.
//It then prompts the user for their information.
cout << "Hello, User. This program will generate ";
cout << "a mailing label and the cost to ship an item. \n";
cout << "Please enter the following information.\n";
cout << "What is your name? ";
getline(cin, name);
cout << "What is your street address? ";
getline(cin, street);
cout << "What is your city? ";
getline(cin, city);
cout << "What is your state? ";
getline(cin, state);
cout << "What is your zip code? ";
cin >> zip;
cout << "What type of item are you shipping?\n";
cout << "1. Letter\n";
cout << "2. Large envelope\n";
cout << "3. Parcel\n";
cin >> package;
cout << "What is the weight in ounces? ";
cin >> weight;
cout << "\n";
//The next line formats the output
cout << fixed << showpoint << setprecision(2);
//This part of the program calculates shipping charges.
if (package != 1 && package != 2 && package != 3)
cout << "Please choose a valid package.";
if (package == 1)
{if (weight < 1.0 && weight > 0.0)
postage = LETTER;
}
{if (weight > 1.0)
postage = (LETTER + (weight * LETTERplus));
}
else if (package == 2)
{if (weight < 1.0 && weight >0.0)
postage = ENVELOPE;
}
{if (weight > 1.0)
postage = (ENVELOPE + (weight * ENVELOPEplus));
}
else if (package == 3)
{if (weight < 1.0 && weight > 0.0)
postage = PARCEL;
}
{if (weight > 1.0)
postage = (PARCEL + (weight * PARCELplus));
}
|