Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 4: \'While\' Loops (10 points) Write a C++ program that prints every in

ID: 3590131 • Letter: E

Question

Exercise 4: 'While' Loops (10 points) Write a C++ program that prints every integer between 330 and 550, inclusive. Use a while loop. Exercise 5: 'Do While' Loops (10 points) Provide a solution to the previous exercise that uses a do-while loop. Exercise 6: 'For Loops (10 points) Provide a solution to the previous exercise that uses a for loop. Exercise 7: Guess-the-Number Game (10 points) Write a program that implements Guess-the-Number game. The program should enter a loop that starts by printing "What year did Pakistan achieve independence?" After printing this, it reads the user response. (Use cin >> n to read the user response.) If the user enters a value less than 1947, the program prints "too early" and continues the loop. If the user enters a number larger than 1947, the program prints "too late" and continues the loop. If the user enters the number 1947, the program prints "you got it" and then terminates.

Explanation / Answer

4)

#include <iostream>

using namespace std;

int main () {

   // Local variable declaration:

   int a = 330;

   // while loop execution

   while( a < 550 ) {

      cout << "value of a: " << a << endl;

      a++;

   }

   return 0;

}

5)

#include <iostream>

using namespace std;

int main () {

   // Local variable declaration:

   int a = 330;

   // do loop execution

   do {

      cout << "value of a: " << a << endl;

      a = a + 1;

   } while( a < 550 );

   return 0;

}

6)

#include <iostream>

using namespace std;

int main () {

   // for loop execution

   for( int a = 1330; a < 550; a = a + 1 ) {

      cout << "value of a: " << a << endl;

   }

   return 0;

}