Answer to Question #99438 in C++ for Caleb

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;
}
1
Expert's answer
2019-12-02T12:28:18-0500

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


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS