1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alisiya [41]
2 years ago
10

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. PLEASE USE C++
Computers and Technology
1 answer:
Goryan [66]2 years ago
5 0

Answer:

PROGRAMMING APPROACH:

  • Define the necessary header file using namespace.
  • Define the main() method.
  • Declare variable inside the function().
  • Print result.

Explanation:

Required C++ Code:

#include<iostream>

#include<string>

using namespace std;

int main()

{

  string condStr;

  int userVal;

  cin>>userVal;

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

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

}

OUTPUT:

-2

-2 is negative.

You might be interested in
What is a 96.1791 weighted gpa in a 4.0 scale?
Oksanka [162]

Answer:

3.85 out of 4

Explanation:

As 96.1791 out of 100 gives 96.1791% calculated below:

Percentage formula: (Obtained value/total value)*100.......eq(1)

Putting values:

= (96.1791/100)*100

= 96.1791%

Now finding 96.1791% of 4:

Putting values in eq (1):

96.1791% = (Obtained value/4)*100

96.1791/100= (Obtained value/4)    (dividing by 100 on both sides)

0.961791 = (Obtained value/4)

4* 0.961791 = Obtained value          (multiplying 4 on both sides)

3.847164 = Obtained value

Then 96.1791% of 4 will be equal to: 0.961791 * 4  = 3.847164

Rounding off the answer to 2 decimal places:

=3.85    (As the digit on 3rd decimal place is greater than 5)

4 0
2 years ago
Write a program that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions
Westkost [7]

Answer:

The Java code is given below with appropriate variable names for better understanding

Explanation:

import java.util.Random;

import java.util.Scanner;

public class MultiplicationQuestions {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       Random rand = new Random();

       int n1, n2, result, total = 0, correct = 0;

       char ch = 'y';

       while(ch == 'y'){

           n1 = 1 + rand.nextInt(9);

           n2 = 1 + rand.nextInt(9);

           System.out.print("What is "+n1+" * "+n2+" ? ");

           result = scan.nextInt();

           if(result==n1*n2){

               System.out.println("Correct. Nice work!");

               correct++;

           }

           else{

               System.out.println("Incorrect. The product is "+(n1*n2));

           }

           System.out.print("Want more questions y or n ? ");

           ch = scan.next().charAt(0);

           total++;

       }

       System.out.println("You scored "+correct+" out of "+total);

   }

}

3 0
3 years ago
Write a Dice Game program that generates two random dice values between 1 and 6 for you, and 2 for the computer. You get to roll
charle [14.2K]

Answer:

#include <iostream>

#include <time.h>

#include <string>

using namespace std;

int main(){

srand(time(NULL));

cout<<"Throw dice"<<endl;

int b =0;

int a=0;

a=rand()%6;

b=rand()%6;

for (int i =0;i<1;i++)

{cout<<"dice one: "<<a<<endl;}

for (int i =0;i<1;i++)

{cout<<"dice two: "<<b<<endl;}

if(a>b)

{cout<<"first dice won"<<endl;}

if(b>a)

{cout<<"second dice won"<<endl;}

else{cout<<"they are same"<<endl;

return main();

}

return 0;

}

Explanation:

/*maybe it help you it is almost done*/

6 0
2 years ago
Which formula is used to measure accuracy?
shepuryov [24]
<span>Gross WPM – Net WPM x 100
So B</span>
7 0
3 years ago
Types of computer viruses<br>​
e-lub [12.9K]

Answer:anti various

Explanation:hope fully this will help u

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is a flash player?
    9·2 answers
  • What i have to care about transmitting data packet from one controller to other controller?
    8·1 answer
  • Yolanda lost her left foot during her military service, but she has been issued a prosthetic that enables her to walk normally,
    13·1 answer
  • A chef writing up her famed recipe for beef stew realizes she has switched parsley and oregano everywhere in the recipe. The che
    13·1 answer
  • In the code snippet, what is the “win” part called in programming?
    12·1 answer
  • An automatic transmission is a mechanism that _
    7·1 answer
  • Question #4
    10·1 answer
  • Help with this please anyone
    15·2 answers
  • Supplies/material used in iron​
    11·1 answer
  • You are writing a program to help compare two sports teams. A sample member of the list scores is [2. 5] where your team scored
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!