Hello digitalFun157,
I take a different approach with your program and 1 of the 1st things I noticed is:
Please enter your first name: Etienne
Please enter your last name: Navarre
Hello Etienne Navarre!
Please enter the height of the box: // Height in what? Inches, feet cm or meters?
Please enter the weight of the box: // Same thing weight in what?
|
The questions here may not make any difference, but it is nice to know what you are working with.
I also noticed that you need a 3rd variable for length. To have a box that is OK at 3 inches high may be good for the program, but what is the length is 5 feet long? Not good.
I did notice that the if statements do nor work properly. I have not worked on that yet because I have another question: given these variables
constexpr int MAXHEIGHT{}, MAXLENGTH{}, MAXWEIGHT{};
what numbers should be inside the {}s? Once I know that I can better understand the if statements.
This bit of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
while (cout << "\n Please enter a number: ") // <--- This has no purpose.
{
int number;
cin >> number;
if (!cin)
{
cout << "\n Invalid input, please try again\n";
cin.clear();
cin.ignore(1024, '\n');
}
else
{
break;
}
/*goto here;*/
}
|
First the variable "number" is defined inside the while loop. The problem when the while loop is finished and the closing } is reached the variable is destroyed. Also you never make use of this variable.
To make the while loop work you need the "else" part.
What would be better and you have a good start on it is:
1 2 3 4 5 6 7 8 9
|
int number{};
while (cout << "\n Please enter a number: " && !(std::cin >> number))
{
cout << "\n Invalid input, please try again\n";
cin.clear();
cin.ignore(1024, '\n');
}
|
Here the lhs of && is very likely to be true all the time. I do not know of any way to make the "cout" statement fail. the rhs of && is the more important part. In the end though it is still a useless bit of code. Removing it makes no difference.
At the beginning of the file you include "<conio.h>". This is not a standard C++ header file and some compilers do not have this file available to use. And what is available is a mere shadow of what it use to be.
Andy