Looping Program

Can someone explain how to do a C++ program that, Ask user how many times they want the computer to print "HI". Print "HI" that many times.

I am not sure on how to start it.
If it could be simple language that would be great.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include<string>

using namespace std;

int main( void )
{
    unsigned int howMany;
    cout << "How many times would you like to say Hi?" << endl;
    cin >> howMany;
    for( unsigned int hiCounter = 0; hiCounter < howMany; ++hiCounter )
    {
        cout << "Hi" << endl;
    }

    return 0;
}


EDIT: I forgot the explanation.

First you declare an unsigned integer variable that you designate to be your # of times you want your message to appear. You then notify the user of the intent of the program (aka what exactly are they inputting, and for what reason?).

Then comes the for loop, which has a designated unsigned integer counting variable that will loop through once for every time the counter is less than the # of times you want.

Btw unsigned int means that the number you designate can never be negative. Same goes for size_t and a few others which I forget.
Last edited on
Topic archived. No new replies allowed.