Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 (userVal

Explanation / 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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote