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
kow [346]
3 years ago
15

Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targe

tValue. Otherwise, print "Not equal".
Computers and Technology
2 answers:
Likurg_2 [28]3 years ago
3 0

Answer:

The program to this question as follows:

Program:

targetValue = 0.3333 #defining variable targetValue and assign value

sensorReading = 0.0 #defining variable sensorReading and assign value

sensorReading = 1.0/3.0 #calculate value in sensorReading variable

Val=sensorReading - targetValue

#calculate the difference and store in Val variable

if (Val < 0.0001): #use of if block to check condition

  print ("Equal")  #print value

else:  #else block

  print ("Not equal") #print value

Output:

Equal

Explanation:

In the above Python program code, there are two variables "targetValue and sensorReading" is defined, in which targetValue store a value, that is "0.3333", and sensorReading holds a value, that is "0.0".

  • In the next step, the "Val" variable is defined, that calculate the difference between both variable, that conditional statement is used.
  • In if block, if the value is less then "0.0001", it will print value "Equal", otherwise, it will go to the else block, that will print "Not equal".
Anna11 [10]3 years ago
3 0

Full Question

Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targetValue. Otherwise, print "Not equal". Ex: If targetValue is 0.3333 and sensorReading is (1.0/3.0), output is: Equal

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double targetValue;

double sensorReading;

cin >> targetValue;

cin >> sensorReading;

if (/* Your solution goes here */) {

cout << "Equal" << endl;

} else {

cout << "Not equal" << endl;

} return 0;

}

Answer:

if (abs(targetValue - sensorReading) <= 0.0001)

Explanation:

Replace

if (/* Your solution goes here */) {

With

if (abs(targetValue - sensorReading) <= 0.0001)

Two values are considered to be close enough if the difference between the values is 0.0001

Splitting the codes into bits;

abs

targetValue - sensorReading

<=

0.0001

The keyword abs is to return the absolute value of the expression in bracket.

This is needed because the expression in the bracket is expected to return a positive value.

To do this the absolute keyword is required.

targetValue - sensorReading returns the difference between the variables

<= compares if the difference falls within range that should be considered to be close enough

0.0001 is the expected range

You might be interested in
F a domain consists of dcs that are running verions of windows server earlier than windows server 2008, what replication method
garri49 [273]
F is the grade I would give you if I were teaching you because your a 2008 Skid. You probably don't even know Html.

5 0
3 years ago
What file format can excel save files as
hodyreva [135]

Answer:

.xlxs

but it supports pretty much any spreadsheet format.

5 0
3 years ago
Identify the true statements about the approach to privacy around the world. a. Uncertainty concerning the nature, extent, and v
Thepotemich [5.8K]

Answer:

a. Uncertainty concerning the nature, extent, and value of privacy is widespread.

d. Significant disagreement about privacy exists within the United States.

6 0
2 years ago
One last question
BlackZzzverrR [31]

Answer:

I love Chipotle!

Explanation:

I don't know, maybe because the food there is really good.

8 0
3 years ago
Read 2 more answers
The process of making raw materials into a finished product is known as
Olin [163]
1.) Business Engineering or Manufacturing :)
<span />
6 0
3 years ago
Read 2 more answers
Other questions:
  • All of the following are stages in the SDLC except _____.
    9·1 answer
  • You are attempting to update a Windows image that has been mounted under C:\mount on your local system. What command must you us
    13·1 answer
  • In mathematics, the factorial of a positive integer n, denoted as n! , is the product of all positive integers less than or equa
    10·2 answers
  • Describe the following software process models using your own words .Your explanation should also provide an example of a softwa
    12·1 answer
  • Please help!! Even if you help a little I will be very thankful!
    7·1 answer
  • Complete the following statement: Sustainability is: Choose all that apply.This task contains the radio buttons and checkboxes f
    10·1 answer
  • This diagram shows a number of computing devices connected to the Internet with each line representing a direct connection.
    11·1 answer
  • Text can be easily moved from one location to another using _____.
    15·1 answer
  • Question 1
    10·1 answer
  • When can screentips be useful? when finding a tab when looking for a command when pinning the ribbon when using a command.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!