Create a conditional expression that evaluates to string \"negative\" if userVal
ID: 1715214 • Letter: C
Question
Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "positive" otherwise. Example output when userVal = -9 for the below sample program:
Create a conditional expression that evaluates to string "negative" if userVal is less than O, and "positive" otherwise. Example output when userVal--9 for the below sample program -9 is negative 1 #include sinclude clostream 2 #include 3 using namespace std, 4. 6string condSir; int userVal- 10 11 12 condStr (userValExplanation / Answer
#include <iostream>
#include<string>
using namespace std;
int main() {
// your code goes here
string condStr;
int userVal;
cin>>userVal;
condStr=(userVal<0)?"negative":"positive";
cout<<userVal<<" is "<<condStr<<"."<<" ";
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.