you forgot to post the code you have written so far
[edit]Oops! you used wrong kind of tags which hid your code. [/edit]
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
When you have all the input, just check if one of them is smaller then 0 and print a error message:
if (tacos < 0 || hotdogs < 0 || [etc...] )
{
cout << "Error message" << endl;
return 0;
}
The || sign are two 'pipes' and mean: 'or'. So if tacos are smaller then 0 OR hotdogs are smaller then 0 OR (etc)
Niek
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
When you have all the input, just check if one of them is smaller then 0 and print a error message:
Or better yet, wrap each input in a while loop that tests for <0:
inp = -1; // force the value to be < 0
while (inp < 0)
{
cout << "Input Value: ";
cin << inp;
if (inp < 0) // test the new value
{
cout << "try again" << endl;
}
}
...and if I don't text wrap right let me know and show me how to do it right
Thanks for asking :) See this
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
you mean
[code=c++]
// your code here
[/code]
The above code tags will add line numbers and colorize your code.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
It's times like this where I think it would be simpler to use a function. Follow the previous advice of WaltP, creating a while() loop. This function will keep looping until the user enters a non-negative integer.
int getPositiveInt() {
int value = -1;
cin >> value;
// keep looping until user enters a non-negative number
while (value < 0)
{
cout << "Error, please enter a non-negative number.\n";
cin >> value;
}
return value;
}
To use, it's very simple:
cout << "Number of hot dogs: ";
hotdogquantity = getPositiveInt();
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Sorry, I didn't read through all your code. You'd have to do it manually for this one:
int sourcreamquantity = 0;
cin >> sourcreamquantity;
// keep looping until user enters less sourcream than tacos
while sourcreamquantity > tacoquantity)
{
cout << "Error, tacos with sour cream must be less than total number of tacos.\n";
cin >> sourcreamquantity;
}
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
After a couple requests and an explanation on how to use them, you still refuse to use CODE tags. Is there a reason for this?
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
while (drinkquantity < 0)
(
This brace should be a curly one { not (}while ( (ans != 'n') && (ans != 'N') );
This while is missing a do { Just place is somewhere after de declaration of ans. READ THIS about using CODE TAGS. If you use indentation, you would have found the problems yourself. Here's a nice thread about it
Niek
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403