If the user inputs 0 and 0, how can i get both "Weight must be greater than zero" and "We do not ship less than 10 miles or more than 3000" without requiring an additional input? is it as simple as removing cin >> weight?
thank you
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
#include<iostream>
#include <iomanip>
using namespace std;
int main();
const int distanceUnit = 500;
double rate = 0;
double shippingCost;
int weight;
int distance;
int distanceunit;
cout << setprecision(2) << fixed;
cout << "Weight of the package in kilograms (max 20 kg):";
cin >> weight;
cout << "Distance the package is to be shipped (min 10 mi, max 3000 Mi):";
cin >> distance;
while (weight <= 0)
{
cout << "Weight must be greater than zero ";
cin >> weight;
}
while (weight > 20)
{
cout << "Weight must be less than twenty kilograms ";
cin >> weight;
}
while (distance < 10 || distance > 3000)
{
cout << "We do not ship less than 10 miles or more than 3000 miles";
cin >> distance;
}
distanceunit = (distance / distanceUnit) + 1;
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
I think you will find this arrangement of more use. I just moved thing around. I moved the first two while loops up because yo are doing them at the wrong time.