Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "non-negative" otherwise. Ex: If userVal is -9, output is:
-9 is negative.
#include <iostream>
int main()
{
int userVal;
std::cout << "Please enter number: ";
std::cin >> userVal;
if(!std::cin)
{
std::cout << "Bad input\n";
return 1;
}
std::cout << userVal << " is "
<< (userVal < 0 ? "negative" : "non-negative")
<< ".\n";
return 0;
}
Comments
Leave a comment