Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

is it correct ? (c++) Section 1.4 Flow of Control EXERCISES SECTION 1.4.3 Exercise 1.16: Write your own version of a program that prints the

is it correct ? (c++) image text in transcribed
image text in transcribed
Section 1.4 Flow of Control EXERCISES SECTION 1.4.3 Exercise 1.16: Write your own version of a program that prints the sum of a set of integers read from cin. 1.4.4 The if Statement Like most languages, C++ provides an it statement that supports conditional exe- cution. We can use an if to write a program to count how many consecutive times each distinct value appears in the input: #include int main() // currval is the number we're counting: we'll read new values into val int curr Val - 0, val = 0; // read first number and ensure that we have data to process if (std::cin>> currval) { int ant - 1; // store the count for the current value we're processing while (std::cin>> val) ( 7 read the remaining numbers if (val - currval) // if the values are the same ++ent // add 1 to cnt else { // otherwise, print the count for the previous salue std::cout int main() { // currval is the number we're counting; we'll read new values into val int currVal = 0, val = 0; // read first number and ensure that we have data to process if (std::cin >> currval) { int cnt = 1; // store the count for the current value we're processing while (std::cin>> val) { // read the remaining numbers if (val == currval) // if the values are the same ++ent; // add 1 to cnt else { // otherwise, print the count for the previous value std::cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions