>>Now I'm just trying to get it to only accept positive input numbers.
So, you want the "int cost" variable, to make sure it is positive, at all times? Right?
I would have created a new function that looks like this:
Code:
int PositivieInteger(char* s, int minimum, int maximum)
{
int returnvalue = 0;
do
{
cout << s; //Writes out the text you sent with it
cin >> returnvalue; //Takes input from the user
}
while(minimum >= returnvalue || returnvalue >= maximum) ;
//If input (returnvalue) is less than minimum value or bigger than maximum, force user
// to input a new number
return returnvalue;
}
int main()
{
int cost = PositiveInteger("Hello, what is the cost of this item?: ", 0, 1000);
//Now the integer "cost" holds the value from the "returnvalue" (input) from the function above...
return 0;
}
You can simply copy paste this code, its working... The function "PositiveInteger", place it above "int main".