Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++. Control Structures // Program Bugs demonstrates bugs in loops and switches. #include #include using namespace std; int main () { ifstream inData; int value;
C++. Control Structures
// Program Bugs demonstrates bugs in loops and switches.
#include
#include
using namespace std;
int main ()
{
ifstream inData;
int value;
bool fileFound;
inData.open("bug.dat");
if (inData)
fileFound = true;
else
fileFound = false;
switch (fileFound)
{
case false : cout
case true :
// do-while loop
{
int counter = 1;
int sum = 0;
do
{
inData >> value;
sum = sum + value;
} while (counter
cout
}
// for loop
{
int sum = 0;
for (int counter = 1; counter
{
inData >> value;
sum = sum + value;
counter++;
}
cout
Exercise 1: Program Bugs is supposed to sum the first ten values on a file and the second tern values on a file. The second ten values are a duplicate of the first ten, so the answers should be the same. The program checks to be sure that the file has been found and halts execution if the flle is not found. Program Buge compiles, but says that the file cannot be found and then the screen freezes. Can you find the problem? Describe it. Exercise 2: Correct the problem and rerun the program. The le cannot be found, but now the program halts correctly. Correct the name of the fle and rerun the program. Exercise 3: What-the screen freezes again? Back to the drawing board. Describe the next error you find. Correct the program and run it again }
break;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started