Ask coding questions

← Back to all posts
"Do your homework" assignment
PrestonHong (0)

I cannot seem to figure out how to use a count controlled loop to display a reminder to "do your homework" 'x' number of times prompted by the user.
#include <iostream>
using namespace std;

int main ()
int reminder;
int initial = 1;
cout << "How many times would you like to be reminded to do your homework? ";
cin >> reminder;

	while (initial <= reminder)
		cout << "Do your homework!" << endl;
return 0;
Giothecoder (41)

Or you could just use a for loop:

int main(){
cout << "how many times would you like to be reminded?\n";
int reminder;
cin >> reminder;
for( int count = 0; count < reminder; count++){
cout << "# " << count + 1 << ": ";
cout << "do your homework!\n";

mwilki7 (623)


while (initial <= reminder)


while (count <= reminder)

The program will leave the while loop only if
count <= reminder becomes a false statement

To make it a false statement, you either have to:
make count bigger than reminder inside the while loop
make reminder smaller than count inside the while loop

To make count bigger: count = count + 1 to make it bigger by 1
To make reminder smaller: reminder = reminder - 1 to make it smaller by 1

Make sure to set count = 1 at the beginning.