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

#include <iostream> using namespace std; int main() { int hour,min; for (hour =

ID: 3544781 • Letter: #

Question

#include <iostream>

using namespace std;

int main()

{

int hour,min;

for (hour = 1; hour <= 11; hour++)

{

for (min = 0; min <= 59; min++)

{

cout << hour << ":" << min << "AM" << endl;

}  }

return 0;

}

1. Type in the above program, add your name and date, compile and run the program

2. The above program is supposed to print all the hours from Midnight to noon. What is the

bug or logic error in the above program? Add the lines to fix it.

4. How many times does the outer loop execute?

5. How many times does the inner loop execute?

Explanation / Answer

#include <iostream>

using namespace std;

int main()

{

int hour,min;

for (hour = 0; hour <= 11; hour++)

{

for (min = 0; min <= 59; min++)

{

cout <<setfill('0')<< hour << ":" << setw(2) << min << "AM" << endl;

} }

return 0;

}





Here is the new Code... In first for loop hour =0 because time should start from 00:00AM to 11:59AM


in cout time should be printed in "hh:mm" format so changed it over there...