#include <iostream> using namespace std; int main() { int hour,min; for (hour =
ID: 3544686 • 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>
#include <ctime>
using namespace std;
int main()
{
int hour,min;
string name = "Steves";
time_t now = time(0);
// convert now to string form
char* dt = ctime(&now);
cout << "My name is " << name << endl;
cout << "The local date and time is: " << dt << endl;
for (hour = 1; hour <= 11; hour++)
{
for (min = 0; min <= 59; min++)
{
cout << hour << ":" << min << "AM" << endl;
} }
return 0;
}
outer loop wil execute 11 times
Inner loop wil execute 11*60 = 660 times
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.