Your writing cin >> negatives (); // Trying to write into a function call Delete the cin and the >> operator.
Also I would suggest you reread about functions and how they work because your not stoping the user from entering a negative number with your function and its not even storing the number it is giving it basically just tells the user if the number is negative then erases everything.
int value ;
std::cout << "enter a non-negative integer: " ;
if( std::cin >> value && value >= 0 ) return value ;
std::cin.clear() ; // clear possible error state
std::cin.ignore( 1000, '\n' ) ; // empty the input buffer
return get_non_negative() ; // and try again
int value = get_non_negative() ;
// use value
Thank you for the example. I tried to implement it into my program but once the user enters positive numbers (after entering negative numbers and being told to enter non-negatives) my equation function will use the initial negative inputs instead of the corrected inputs.
I placed the "get_non_negative()" function after the cin >> in my input coding
1 2 3 4 5 6 7 8 9 10
void userinput(double &feet, double &inches)
cout << "Enter number of feet: ";
cin >> feet;
cout << "Enter number of inches: ";
cin >> inches;
I tried inserting the get_non_negatives() three different positions (before cout, after, and after cin) to no avail.