i got the sorta of the being im confuse if i should use a switch or a loop
the display should look like this:
Please enter the truck number and weight: 1 45000
Your truck is ready to roll.
Please enter the truck number and weight: 2 30000
Your have exceeded your allowable weight allowance.
Please enter the truck number and weight: 0 40000
Your entered a invalid truck number or weight.
…
All trucks have weighed-in.
and weigh-in value is compared to the established maximum weight limit. A message is displayed to tell the user weather the truck is within weight limits.
here wat i started
#include <iostream>
using namespace std;
int main()
{
string trucknum[4] = { "1", "2", "3", "4"};
int MaxWeightLimit = { 50000, 25000, 20000, 35000};
int truck;
cout << "Please enter the truck number and weight: ";
cin >> truck;
First you need to build in a way to exit the program.
I would do it with truck # = 0.
With the code you posted, I don't see a reason to make your array use string. I would use int.
Your not assigning the values weight limit to the array.
and finally, Your not getting the weight from the user, your only getting the truck number.
In my example below, I am showing the max weight for each truck. This is done mainly for building the code and trouble shooting, you may want to remove that for your finished program. But this will get you started.
#include <iostream>
usingnamespace std;
int main()
{
int trucknum[4] = { 1, 2, 3, 4};
trucknum [1] = 50000;
trucknum [2] = 25000;
trucknum [3] = 20000;
trucknum [4] = 35000;
// int MaxWeightLimit[4] = { 50000, 25000, 20000, 35000};
int truck=0;
int weight=0;
cout << "Please enter the truck number and weight: ";
cin >> truck >> weight;
//while (truck >= 0)
if ((truck >= 1) && (truck <= 4))
{
cout << "Max Weight: " << trucknum[1] << endl;
if (truck==1)
{
if ((weight >=0) && (weight <= trucknum[1]))
{
cout << "Your truck is ready to roll." << endl;
}
else
{
cout << "Your have exceeded your allowable weight allowance." << endl;
}
}
cout << "Max Weight: "<< trucknum[2] << endl;
cout << "Max Weight: "<< trucknum[3] << endl;
cout << "Max Weight: "<< trucknum[4] << endl;
}
else
{
cout << "Your entered a invalid truck number or weight." << endl;
}
return 0;
}
PS. This example doesn't check the weight of the truck as valid, only the truck number. If you want to to verify the weight is a valid value, you'll need to add that.
The code above will have a range error. The reason is because this trucknum [4] = 35000;. Remember arrays start at 0 not 1. You should always follow this convention.
thanks for that but i was trying put any number that donst exceeded the weigh
thats my only problem. i really appericiate it , it did help me compare mine.