Question: I have asked this question before, but the code I was given does not continue reading the rest of the numbers after the negative number

I have asked this question before, but the code I was given does not continue reading the rest of the numbers after the negative number is entered. If the user enters the negative number as the 3rd number, I don't want the loop to stop there before they get to enter all 50 numbers. After they have entered all 50 numbers including the negative number, I want to then display the numbers they've entered prior to the negative number. to the output file.

Here is the code in C++

#include using namespace std; void read_data_function(); void display_numbers(); void display_all_numbers(); int stack[50],top=-1,i; void read_data_function() { for(i=0;i<50;i++) { top++; cin>>stack[i]; if(stack[i]<0) { break; } } } void display_numbers() { cout<<" "; cout<<"displaying all numbers you entered prior to negative number"<<" "; for(i=0;i

cout<=0) { cout<

read_data_function(); display_numbers(); display_all_numbers(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!