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]
2 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]2 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]2 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
Application of computer in insurance​
Free_Kalibri [48]

Answer:

To keep a list of insured members in the offices.

Explanation:

Compunters can be used to keep records of insured individual and their details

7 0
2 years ago
Write a structured algorithm that prompts the
MA_775_DIABLO [31]

Answer:

Step 1 : Start

Step2 : Input first number, num1

Step3 : Input second number, num2

Step4 : product - - > num1 * num2 (product of num1 and num2)

Step5 : Input product, myanswer

Step6 : comparison - - - > correct or incorrect based on myanswer and product

Step6: print(comparison)

Step7: End

Explanation:

Algorithm is a sequence of instructions a computer is expected to follow to solve a particular problem.

Required :

Two inputs ; num1 and num2

Expected output

Algorithm :

Step 1 : Start

Step2 : Input first number, num1

Step3 : Input second number, num2

Step4 : product - - > num1 * num2 (product of num1 and num2)

Step5 : Input product, myanswer

Step6 : comparison - - - > correct or incorrect based on myanswer and product

Step6: print(comparison)

Step7: End

The two numbers to multiply are entered ; the product is calculated by the program ; the the user inputs his or her own expecteted product ;

Both are compared and the output of the comparison is displayed (either correct oe incorrect)

8 0
2 years ago
Which of the following conditions will maximize the amount of interest you earn
choli [55]
The answer is the amount of money you put in it, brainliest please.
4 0
3 years ago
Salvado has a flash dish of is GB
exis [7]

Answer:

About 1,655 files or exactly 1655.646315789473684210526315785

1578

Source(s):

1.5 gb = 1,500 mb<---wrong right --->1536

Explanation:

6 0
2 years ago
The data selected to create a table must include
Novay_Z [31]

The column names and data types.

4 0
2 years ago
Read 2 more answers
Other questions:
  • Use the Internet and other sources to research the two disadvantages of standard biometrics: cost and error rates. Select one st
    10·1 answer
  • If you are working on a document and want to have Word automatically save the document every minute, what steps should you use t
    13·1 answer
  • #We've started a recursive function below called #measure_string that should take in one string parameter, #myStr, and returns i
    5·1 answer
  • When evaluating portable CD players, you consider price, the sound quality, and ease of using the controls. These are your _____
    8·2 answers
  • Which questions should you ask yourself when performing research online?
    9·1 answer
  • What keyboard functions lets you delete words
    9·2 answers
  • Ian kno da answer tell me
    7·2 answers
  • I know I'm asking for a lot. But this is my last question. If we do it I pass my semester. help please.
    15·1 answer
  • What economic impact will this disaster have on people? Select three options.
    11·1 answer
  • What is the digital revolution and how did it change society?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!