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
cestrela7 [59]
3 years ago
14

c++ Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is c

onsidered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7. Write some code that uses a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code exits the loop it should print the number of consecutive duplicates encountered. In the above case, that value would be 3.
Computers and Technology
2 answers:
Ludmilka [50]3 years ago
8 0

Answer:

int firstNumber,secondNumber = -1, duplicates = 0;

do {

   cin >> firstNumber;

   if ( secondNumber == -1) {

       secondNumber = firstNumber;

   }else {

       if ( secondNumber == firstNumber )

           duplicates++;

       else

           secondNumber = firstNumber;

   }

} while(firstNumber > 0 );

 

cout << duplicates;

Explanation:

Write some code that uses a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code exits the loop it should print the number of consecutive duplicates encountered. In the above case, that value would be 3. We test the following on a C++ platform.

int firstNumber,secondNumber = -1, duplicates = 0;

do {

   cin >> firstNumber;

   if ( secondNumber == -1) {

       secondNumber = firstNumber;

   }else {

       if ( secondNumber == firstNumber )

           duplicates++;

       else

           secondNumber = firstNumber;

   }

} while(firstNumber > 0 );

 

cout << duplicates;

Ksivusya [100]3 years ago
4 0

<u>Answer:</u>

<em>int fNumber,scndNumber = -1,  </em>

<em>dup = 0; </em>

<em>do { </em>

<em>cin >> fNumber; </em>

<em>if ( scndNumber == -1) { </em>

<em>scndNumber = fNumber; </em>

<em>} </em>

<em>else { </em>

<em>if ( scndNumber == fNumber ) </em>

<em>duplicates++; </em>

<em>else </em>

<em>scndNumber = fNumber; </em>

<em>} </em>

<em>} while(fNumber > 0 );  </em>

<em>cout << dup; </em>

<u>Explanation:</u>

Here three variables are declared to hold the first number which is used obtain all the inputs given by the user, second number to hold the value of <em>last encountered number and “dup” variable to count the number of duplicate values.</em>

<em>“Do-while”</em> loop help us to get the input check whether it is same as previous input if yes then it <em>adds to the duplicate</em> value otherwise the new previous value if stored.

You might be interested in
How does the speaker feel about traditional forms of poetry
Salsk061 [2.6K]
A speaker sometimes is not able to capture the intended details since it is affected by homophones.
7 0
3 years ago
Read 2 more answers
What are the three general methods for delivering content from a server to a client across a network
Tju [1.3M]

Answer:

Answered below.

Explanation:

The three general methods consist of unicasting, broadcasting and multicasting.

Casting implies the transfer of data from one computer (sender) to another (recipient).

Unicasting is the transfer of data from a single sender to a single recipient.

Broadcasting deals with the transfer of data from one sender to many recipients.

Multicasting defines the transfer of data from more than one sender to more than one recipients.

8 0
2 years ago
14. The Internet may best be compared to a/an
finlep [7]
From that particular list, the item that best compares to the internet
is B. a large network of roads.
7 0
3 years ago
Read 2 more answers
What is the name of the interface that uses graphics as compared to a command-driven interface?
bonufazy [111]
Answer = GUI (Graphical User Interface)
4 0
3 years ago
What is the body of scientific knowledge based on?
ANTONII [103]
It depend on all such as guess ,observation ,hypothesis and etc
3 0
2 years ago
Read 2 more answers
Other questions:
  • Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author'
    14·1 answer
  • Some technologies like vertical farming have a number of negative effects. Which is a negative outcome of this technology? A. In
    10·1 answer
  • ………………….. is the process of causing a system variable to conform to some desired value. Options Control feedback Design none of
    9·1 answer
  • A parent is browsing through a shopping website, looking for blue-colored striped socks for her child. She is fine if the socks
    15·1 answer
  • What is one of the first power tools you’ll need as electrician
    15·1 answer
  • 8.7 Code Practice: Question 2 edhesive
    14·2 answers
  • One rule in the Java programming language is that you have to place a semicolon at the end of each statement. What is this rule
    10·2 answers
  • The Internet is a worldwide communications network. Which device connects computer networks and computer facilities?
    11·1 answer
  • Write the technical terms for the following statements: The repeated working capacity of computer.
    15·1 answer
  • Fiona was talking to her colleagues about how advancements in digital technology had a negative effect on her life. Which aspect
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!