program to read 10 positive integers, until the value

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a short C++ program to read 10 positive integers, until the value -1 is read and print the sum of the values.

Expert Solution
Step 1

Summary

C++ Input taking:
The C++ cin object is used to receive input from the standard input device. H. Accepting keyboard. This is an instance of class istream. It is linked to the standard C input stream stdin. The extraction operator (>>) is used with the cin object to read the input. The Extract operator extracts data from the object cin entered using the keyboard.


The positive integers 1, 2, 3, 4... are called natural numbers.

This program takes a positive integer from the user (assuming the user entered n) and prints the values ​​1+2+3+...+n.
duplicates. The input is read in two places instead of one. Duplicate code creates the possibility of updating one but not the other when you change the program.
more codes. Reads and tests are split over three lines instead of one. This makes it difficult to read and maintain. Possible error. The GCC I/O library used by DevC++ handles this nicely. However, I've used a system that behaves differently in a while (cin) test depending on whether there is a space after the last value. please think about it. The problem is very subtle. How does the I/O system know not to read the space after the last value? Well, it can't really know, so I'll make some assumptions. Not all systems make the same assumptions about how to handle trailing spaces after the last value.

 

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education