Question #99438

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>
#include <string>
using namespace std;

int main() {
string condStr;
int userVal;

cin >> userVal;

condStr = /* Your solution goes here */;

cout << userVal << " is " << condStr << "." << endl;

return 0;
}

Expert's answer

condStr = (userVal < 0) ? "negative" : "non-negative";


LATEST TUTORIALS
APPROVED BY CLIENTS