answer.
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]
1 year 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]1 year 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]1 year 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
Write code which takes a sentence as an input from the user and then prints the length of the first word in that sentence.
Afina-wow [57]

import java.util.Scanner;

public class U2_L3_Activity_Four {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a sentence.");

       String sent = scan.nextLine();

       int count = 0;

       for (int i = 0; i < sent.length(); i++){

           char c = sent.charAt(i);

           if (c != ' '){

               count++;

       }

           else{

               break;

           }

       

   }

       System.out.println("The first word is " + count +" letters long");

   

   }

}

We check to see when the first space occurs in our string and we add one to our count variable for every letter before that. I hope this helps!

7 0
1 year ago
____ is a program placed on a computer without the user's knowledge that secretly collects information about the user
Scrat [10]
<span>Spyware is a program placed on a computer without the user's knowledge that secretly collects information about the user.
</span><span>The spyware gathers information and can send this information to another program or entity which can take control over the device or use personal information to harm the user. </span>
7 0
1 year ago
A(n) _____ is the highest educational degree available at a community college. master bachelor associate specialist
baherus [9]
<span>An associate's degree requires two years of academic study and is the highest degree available at a community college</span>
5 0
2 years ago
Read 2 more answers
3.34 LAB: Mad Lib - loops in C++
Ganezh [65]

Answer:

A Program was written to carry out some set activities. below is the code program in C++ in the explanation section

Explanation:

Solution

CODE

#include <iostream>

using namespace std;

int main() {

string name; // variables

int number;

cin >> name >> number; // taking user input

while(number != 0)

{

// printing output

cout << "Eating " << number << " " << name << " a day keeps the doctor away." << endl;

// taking user input again

cin >> name >> number;

}

}

Note: Kindly find an attached copy of the compiled program output to this question.

7 0
1 year ago
Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessar
sergejj [24]

// This command takes input from the user.

Scanner input = new Scanner(System.in);

int response= input.nextInt();

// Making the variables required

int noCount =0 ;

int yesCount =0;

// Checking the response if it is 1 or 2 and reporting accordingly

if(response == 1 || response ==2){

 yesCount+=1;

 System.out.println("YES WAS RECORDED");

}

// Checking if the input is 3 or 4 then printing the required lines

else if (response == 3 || response ==4){

noCount+=1;

 System.out.println("NO WAS RECORDED");

}

// if the input is not valid than printing INVALID

else{

System.out.println("INVALID");

}

 

 

 

6 0
2 years ago
Other questions:
  • Which of the following people is required by law to wear a seat belt? A. The operator of a truck weighing more than 26,000 lbs B
    15·1 answer
  • A slide contains three text boxes and three images that correspond to the text boxes. Which option can you use to display a text
    5·2 answers
  • Which computer applications can Mr. Crowell use to make the classroom learning more stimulating and interesting? Mr. Crowell has
    9·2 answers
  • Write a static method, getBigWords, that gets a single String parameter and returns an array whose elements are the words in the
    15·1 answer
  • Represent the logic of a program that allows the user to enter a value for one edge of a cube. The program calculates the surfac
    10·1 answer
  • 15) The codes for class Hotel has been defined in two separate files Hotel.h, and Hotel.cpp. Which of the following statements i
    12·1 answer
  • 1. The precious metals needed to make computer chips, graphic cards, and transistors are found in only a small population of cou
    8·1 answer
  • A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be true in ord
    5·2 answers
  • You are a security consultant and have been hired to evaluate an organization's physical security practices. All employees must
    6·1 answer
  • A homeowner uses a smart assistant to set the house alarm, get packages delivery updates, and set time on the outdoor lights. Wh
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!