Q:

Compile and run the program from this section giving it only equal values as input. Run it again giving it values in which no number is repeated

0

Compile and run the program from this section giving it only equal values as input. Run it again giving it values in which no number is repeated.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

int main() {
  int curVal = 0, val = 0;
  if (std::cin >> curVal) {
    int cnt = 1;
    while (std::cin >> val) {
      if (val == curVal)
        ++cnt;
      else {
        std::cout << curVal << " occurs "
                  << cnt << " time(s)" << std::endl;
        curVal = val;
        cnt = 1;
      }
    }
    std::cout << curVal << " occurs "
              << cnt << " time(s)" << std::endl;
  }
  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now