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 is the build in libary function to compare two strings?​
worty [1.4K]

Answer:

strcmp() is a built-in library function and is declared in <string. h> header file. This function takes two strings as arguments and compare these two strings lexicographically.

Explanation:

Hope it helps

3 0
3 years ago
Explain the components of Information System?​
slavikrds [6]

Answer:

An information system is essentially made up of five components hardware, software, database, network and people. These five components integrate to perform input, process, output, feedback and control. Hardware consists of input/output device, processor, operating system and media devices.

Explanation:

7 0
3 years ago
Write a short note on Computer<br>impact on<br> our society?​
Vesna [10]

well not a note but here are some few points

Explanation:

1 Computers can have the huge impact on employment of people like job and other stuff.

2 lots of human can be jobless or unemployed

3 it can cuz impact on the health of peoples

4 it also can make us lazy and and lack of self knowledge

8 0
2 years ago
Read 2 more answers
What is the value of count after this nested FOR loop executes fully.
Alisiya [41]

Answer:

168 (although the =< must be corrected to <=)

Explanation:

int count = 0;

for (int row = 4; row <= 15; row++)

for (int col = 0; col < 13; col = col +2)

count+=2;

The inner for loop runs 7 times (for col = 0,2,4,6,8,10,12). Anything higher is not less than 13. Therefore the inner loop increments count by 2 seven times, i.e. it increments count by 14.

The outer for loop runs 12 times (for row = 4,5,6,7,8,9,10,11,12,13,14,15).

If the count is incremented by 14 twelve times, you are incrementing it by 14*12 = 168.

Therefore the count goes from 0 to 168 after the nested loops.

5 0
3 years ago
Which solution eliminates the need for dedicated high-speed WAN connections between sites
s344n2d4d5 [400]

Answer:

running in the 90 s intensifies

Explanation:

4 0
2 years ago
Other questions:
  • Morgan is the operations manager for a national appliance distributor. The company has offices throughout the United States. Com
    7·1 answer
  • Constructors ________. initialize instance variables when overloaded, can have identical argument lists when overloaded, are sel
    11·1 answer
  • How do humans feel about being abducted?
    12·2 answers
  • 15. The text of a desktop publishing document is often created using
    6·2 answers
  • Explain one thing you will start doing as a passenger.
    10·2 answers
  • What category of sensory receptors are sensitive to touch sound and motion?
    10·1 answer
  • Before measuring resistance of a component, be sure:
    8·1 answer
  • write a script to check command arguments. Display the argument one by one (use a for loop). If there is no argument provided, r
    6·1 answer
  • Users who are connecting to an NLB cluster have been complaining that after using the site for a few minutes they are prompted t
    15·1 answer
  • In one to two sentences, describe how you would add a new slide to your presentation.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!