Analyze the following program: #include <iostream> #include <iomanip> using name
ID: 3630791 • Letter: A
Question
Analyze the following program:#include <iostream>
#include <iomanip>
using namespace std;
//Program name: TaskTwo
int main(void)
{
int I=5;
while ((I < 10) && (I > -10))
{
if (I == -3)
{
cout<<"P "; I = I + 8;
}
if (I == -2)
{
cout<<'?'; I = I + 7;
}
if (I == -1)
{
cout<<'X'; I = I - 3;
}
if (I == 0)
{
cout<<'O'; I = I + 2;
}
if (I == 1)
{
cout<<'d'; I = I * 2;
}
if (I == 2)
{
cout<<'O'; I = I - 5;
}
if (I == 3)
{
cout<<'!'; I = I / 3;
}
if (I == 4)
{
cout<<'*'; I++;
}
if (I == 5)
{
cout<<'L'; I = I % 5;
}
if (I == 6)
{
cout<<'T'; I--;
}
} // while I
cin.get(); cin.get();
return 0;
} // main
Problem: Modify the program TaskTwo to correct the error observed in Activity 2.3. The program should give one line of output: LOOP. After testing your program for correctness, print and turn in the modified program.
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
//Program name: TaskTwo
int main(void)
{
int I=5;
while ((I < 10) && (I > -10))
{
if (I == -3){cout<<"P "; I = I -7;}
if (I == -2){cout<<'?'; I = I + 7;}
if (I == -1){cout<<'X'; I = I - 3;}
if (I == 0){cout<<'O'; I = I + 2;}
if (I == 1){cout<<'d'; I = I * 2;}
if (I == 2){cout<<'O'; I = I - 5;}
if (I == 3){cout<<'!'; I = I / 3;}
if (I == 4){cout<<'*'; I++;}
if (I == 5){cout<<'L'; I = I % 5;}
if (I == 6){cout<<'T'; I--;}
} // while I
cin.get();
cin.get();
return 0;
} // main
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.