|
|
For this program, the shipment methods have to be char variables. |
# include <iostream> # include <iomanip> using namespace std; int main () { // Declare variables for shipment type char R, P, O; // Assign variable to delivery type // int type; // Assign variable to package weight and price float weight, price; // Ask user to specify shipping service and weight of package cout << "Specify service type (R/P/0) and package weight (XX.X)" << endl; cin >> char >> weight; // Assign cost to package switch (char) { case 'R': if (weight < 2) price = (1 * weight); if (weight > 2 && weight <= 6) price = (1.5 * weight); if (weight > 6 && weight <= 10) price = (2 * weight); if (weight > 10) price = (2.5 * weight); break; case 'P': if (weight < 2) price = (3.5 * weight); if (weight > 2 && weight <= 6) price = (5.5 * weight); if (weight > 6 && weight <= 10) price = (7.5 * weight); if (weight > 10) price = (9.5 * weight); break; case 'O': if (weight < 2) price = (11.5 * weight); if (weight > 2 && weight <= 6) price = (16.5 * weight); if (weight > 6 && weight <= 10) price = (21.5 * weight); if (weight > 10) price = (26.5 * weight); break; } // Limit final output to 2 decimal places cout << setprecision(2) << fixed; // Display the package info and shipping price cout << "The service you chose is " << char << endl; cout << "The weight of your package is " << weight << endl; cout << "The shipping charge for this package is " << price << endl; return 0; } |
Ok, I tried making some changes but now it won't even compile. I'm honestly not sure how to properly declare the 3 char variables and have the program select from them. |
I tried changing the variable type and now it won't even compile |
char type;
and don't change anything else.