You should not use the variable "count" if you use "using namespace std;" because std::count is a function name. (
http://www.cplusplus.com/reference/algorithm/count/)
This kind of misuse of reserved names can cause very "interesting" behavior in your program. To prevent problems it is therefor recommended to not use "using namespace std;" and just put std:: in front of the functions you from the standard library that you want to use.
Your program termination
did not work because of two mistakes:
1. You did not close your brackets.
2. You declares the variable confirm inside the do-while loop, but the condition is not part of the inside of the loop and therefor the variable has to be declared before you start the loop.
For the number validation I would use:
1 2 3 4 5 6 7 8 9 10 11 12
|
bool is_a_number(std::string userInput, int& numberOfProducts)
{
try
{
numberOfProducts = std::stoi(userInput); // if the string does not contain a number, the catch will be executed.
return true;
}
catch(...)
{
return false;
}
}
|
and below that in the main program:
1 2 3 4 5 6 7 8
|
if (is_a_number(userInput, numberOfProducts))
{
const int price = 25.00;
int subtotal = numberOfProducts*price;
int tax = subtotal*0.08;
int total = subtotal + tax;
cout << "Your total is: $"<< total;
}
|
Some other notes:
If this was real I have just sold you a lot of shirts and you own me a lot of money. Maybe you should consider only accepting positive numbers for order quantity :-p.
Also, I would personally use complete words for your variables a and c, this is a habit that is going to cost you a lot of time in the future.
And I would declare them as strings and apply the same validation on them. If you enter "short" for arms the current response of your program is "interesting".
I hope it helps you a bit.
Kind regards, Nico