Need help repeating a message after user inputs an integer.

Write your question here.
I need a program that can ask the user to enter a non-zero, positive integer N first. Then the program will allow the user to enter the following N integers, one at a time. After the user has input all N integers the program will output the min, max and average of all the integers.
I'm also allowing the user to enter negative integers.

I am very very new to C++, my programming class started 2 weeks ago and this seems like a really hard problem. My text book doesn't have anything on this and the professor just expects us to "think" about how to solve it. Well I've been thinking for several days and can't come up with a solution. The following code is the farthest I've gotten.
1
2
3
4
5
6
7
8
9
10
11
12
  // Display a prompt.
cout <";

// Input n.
cout << "Please enter N: ";
int n = 0;
cin >> n;

if (n >= 0)
{
// Output message n times.
for (int j=0; j 
Do you know how to write a loop that repeats n times?
No, I'm unfamiliar with loops that mix text and numbers. I would know how to repeat a number n times, but not a text that allows user input each times.
welcome aboard! I'm pretty new myself, and already battling mystical shit and erratic compiler reactions! And I know how to set up a repeating message...

to print these out a billion times, you have to create a for loop first. Looks like this:

1
2
3
4
5
6
7
8
9
10
using namespace std;

int print = 0;

int main()
{

    for(print == 0; print < 10; print++)
        cout << "message message message\n";
    }


Here is the basic breakdown:

print == 0; checks if the value print is set to 0, that's the first conditional part of the for loop.
If that's not met, the loop will not start.

print < 10; will check if the value of print is below 10, and is the second conditional part.
It will continue repeating the loop, until it reaches that point, and stop.

print++; will keep increasing the value of print by 1 each time the loop has run through it's own code. This is what the conditions are mainly for, and stops the loop from literally running a billion times.

I can also show you how to mix "text" with values. Here is one way, using this exact loop:

1
2
3
4
5
6
7
8
9
10
using namespace std;

int print = 0;
int result = 2000;

int main()
{
    for(print == 0; print < 10; print++)
        cout << "Aaaaand the result is: " << result << "!\n";
    }


I added in int result = 2000, and ordered the program to print out the value of result. You can create a giant congo-line of text and values and whatnot, cout will print it all out without discrimination, one right after the other. Just remember using the << arrows, because you can't mix raw values and "text" together, you have to seperate it with the <<. Oh, and it must always point to cout <<.

And lastly, and that's just my opinion, you got to make ULTRALIBERAL use of "\n", it's pure bueno for the eyes and makes everything a lot easier to decipher.
1
2
3
for(print == 0; print < 10; print++)
        cout << "message message message\n";
    }


print == 0; checks if the value print is set to 0, that's the first conditional part of the for loop.
If that's not met, the loop will not start.


That's just not true. The For loop syntax first expects a expression or declaration statement, typically a loop counter. The only condition that's ever evaluated is the second attribute.
Yeah, and it only goes to the third statement after evaluating an interation
Topic archived. No new replies allowed.