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
What does Adsl stand for?
spin [16.1K]
ADSL stands for Asymmetric Digital Subscriber Line


7 0
3 years ago
Read 2 more answers
What type of volcano is Dukono
ValentinkaMS [17]
Dukono is an active volcano located in the northern part of Halmahera island, Indonesia. It has a broad profile and is capped by compound craters.
8 0
2 years ago
Select the correct answer from each drop-down menu.
tia_tia [17]

Answer:

<dd> tag is used

Explanation:

The <dd> tag is used in HTML document to explain set of terms. The <dd> tag list is used in conjunction with the <dl> term. Inside a <dd> tag we can insert text, sentence, paragraph or links. There are 4 primary tags to build any website. Every HTML document begins and ends with HTML tag.

6 0
3 years ago
One of the implications of price elasticity of technology products is that:
Stels [109]

Answer:

 The main implication of the price elasticity in the various technology products may lead increase the productivity of the products as customers buy more products due to the cheaper price of the product.

as die to the time lower costs will prompt higher deals volumes, which may compensate for the lower overall revenue. Now and again, raising the cost of your item or administration will prompt higher overall revenues yet will bring down your business volumes.

It also offer many advantages like high reliability, security and the scalability.

8 0
3 years ago
Which strategies for effective presentations is Ian using in his opening? Check all that apply.
Fofino [41]

Answer:

A. using a hook in his opening

B.  detailing the speech’s objectives

E. letting his audience know what to expect

Explanation:

Opening his speech using a quotation is a strategy of using a narrative hook, or simply hook, by Ian. Giving a grand and enticing opening is what makes an audience to pay attention and listen to what the speaker has to say in his speech. So, first strategy used by Ian is using a hook in his opening.

Another strategy used by Ian is giving objective details of his speech. By outlining what he will be covering in his speech, Ian is letting his audience know what to expect from the speaker and his speech, and also gave details of his speech.

So, option A, B, and E are correct.

5 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following is a key feature of SmoothWall? Weak traffic graphs and bandwidth bars Universal Plug and Play support DM
    7·1 answer
  • The first commercially available digital camera was which of the following?
    9·1 answer
  • In French class, Blue puts on a visor and the environment changes to that of a café in Paris. Which of the following terms descr
    12·2 answers
  • How can you say that a painting is real? ​
    7·2 answers
  • Please choose the correct answer please tell fast​
    15·1 answer
  • Discuss the impact printer and its types in detail?
    7·1 answer
  • Who is the father of computer?​
    14·1 answer
  • The optical phenomenon that allows us to view rapidly changing still images as moving images is called _______.
    15·2 answers
  • Plsssssssss help me​
    8·1 answer
  • Briefly describe the working of computer processing system?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!