Loop to output (5) random numbers:

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{ // Start
srand(time(0));
int c = rand()% 49 + 1;
cout << c;
return 0;
} // End

Would you please add the codes to output (5) random numbers
example: 5,7,19,49,8

Would you please read about loops from: http://www.cplusplus.com/doc/tutorial/control/
Hello samtheman,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

It is your job to write the code or at least try. It is my job to help you understand what is wrong and hoe you might correct it. If I write the code for you what do I get out of it and what do you learn?

A few blank lines and proper indenting would make your code easier to read.

There is one line of code that should be in a loop. The question is should it be a do/while, for or while loop?

Hope that helps,

Andy
Two, Andy. Two lines of the current code, although they could be a oneliner.
@keskiverto,

Thank you I see your point now. My bad.

Andy
Handy Andy wrote:
The question is should it be a do/while, for or while loop?

huh? What difference does it make if it's a for or a while loop? One can easily be converted into the other. And do...while is only to guarantee a run-through even if the condition is not met the first time, so mentioning this construct is distracting from the essence of the problem.

@samtheman One other minor thing to check -- are you sure you want to output from 1 to 49? Usually people ask for "round" number ceilings, like from 1 to 10, 1 to 50, 1 to 100, etc.
Topic archived. No new replies allowed.