This is a programming code. I cannot correct the errors without the knowledge of the programming language and the specific requirements of the program.
Added by Keith O.
Step 1
Step 1: Identify the programming language used in the code. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 78 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
The file has: 65 78 65 89 25 98 -999 87 34 89 99 26 78 64 34 -999 -999 23 99 98 97 26 78 100 63 87 23 -999 62 35 78 99 12 93 19 -999 C++ will not output correctly #include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { int sum; int num; int counter; ifstream infile; infile.open("Exp_5_24.txt"); counter = 0; infile >> num; while (infile) { sum = 0; sum = sum + num; infile >> num; while (num != -999) { sum = sum + num; infile >> num; } cout << "Line " << counter + 1 << ": Sum = " << sum << endl; counter++; infile >> num; } infile.close(); return 0; } Line 1: Sum = 420 Line 2: Sum = 511 Line 3: Sum = -305 Line 4: Sum = 398 This is what it is supposed to be: Line 1: Sum = 420 Line 2: Sum = 511 Line 3: Sum = 0 Line 4: Sum = 694 Line 5: Sum = 398
Akash M.
int main() { int X[7] = {0}; int k = 2; ifstream FlData("F1.txt"); FlData >> X[k]; while (!FlData.eof()) { k++; FlData >> X[k % 6]; } return 0; }
Integer numVals is read from input representing the number of integers to be read next. Use a loop to read the remaining integers from input. For each integer read in the loop, output "quantity >>" followed by the integer. End each output with a newline. Ex. If the input is: 3 70 95 80 Then the output is: quantity >> 70 quantity >> 95 quantity >> 80 #include <iostream> using namespace std; int main() { int numVals; int value; cin >> numVals; for (int i = 0; i < numVals; i++) { cin >> value; cout << "quantity >> " << value << endl; } return 0; }
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD