I am unsure where I am going wrong in my code. I am trying to create a program that allows the user to enter a number, the program ends when the user enters 0. The program also needs to show the sum of the numbers entered. When I compile and run the code, it shows the endless "Please ebter a number (0 to terminate):".

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
icon
Concept explainers
Question
100%

I am unsure where I am going wrong in my code. I am trying to create a program that allows the user to enter a number, the program ends when the user enters 0. The program also needs to show the sum of the numbers entered. When I compile and run the code, it shows the endless "Please ebter a number (0 to terminate):".

1
// Start
Declarations
number value
number sum
Initialize sum to 0
output "Please enter a number (0 to terminate):"
input value
while value != 0
sum = sum + value
output "please enter a number (0 to terminate):"
endwhile
//
output "The value of sum is" sum
// Start
#include <iostream>
#include <string>
using namespace std;
int main()
{
int value;
int sum = 0;
cout <«< "Please enter a number (0 to terminate):" << endl;
cin >> value;
28
29
B0
31
32
3
while(value != ®)
{
sum = sum + value;
cout <« "Please enter a number (0 to terminate):" <«< endl;
}
cout << "The value of sum is" << sum << endl;
Transcribed Image Text:1 // Start Declarations number value number sum Initialize sum to 0 output "Please enter a number (0 to terminate):" input value while value != 0 sum = sum + value output "please enter a number (0 to terminate):" endwhile // output "The value of sum is" sum // Start #include <iostream> #include <string> using namespace std; int main() { int value; int sum = 0; cout <«< "Please enter a number (0 to terminate):" << endl; cin >> value; 28 29 B0 31 32 3 while(value != ®) { sum = sum + value; cout <« "Please enter a number (0 to terminate):" <«< endl; } cout << "The value of sum is" << sum << endl;
Please enter a number (e to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (0 to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (e to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Please enter a number (e to terminate):
Please enter a number (0 to terminate):
Please enter a number (e to terminate):
Please enter a number (0 to terminate):
Please enter a number (0 to terminate):
Transcribed Image Text:Please enter a number (e to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (0 to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (e to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate): Please enter a number (e to terminate): Please enter a number (0 to terminate): Please enter a number (e to terminate): Please enter a number (0 to terminate): Please enter a number (0 to terminate):
Expert Solution
The problem:

Hey! Hope you are doing good!

The basic Problem of the code that you have provided is that you have somehow told the computer to repeat "Please Enter a Number (0 to terminate)" until the value does not change to 0, since it is written inside the loop.

The very first time when we input a number other than 0 then the value of the variable "value" changes and it is not zero, so the computer gets stuck in an infinite loop until the program is terminated forcefully.

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Operators
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