Hey guys, I'm new to C++ and in desperate need of help. I'm trying to write a program that is like powerball. I need to generate six random numbers. The first five numbers need to be in the range of 1-55 while the sixth number is in the range of 1-42. The program needs no input from the user and should generate random numbers in those ranges everytime on startup. Also, the header which is just "Powerball", and all six identical random numbers need to be written to text file named "Powerball.txt which should be located in the solution folder of the Visual Studios Project. I'm new to both random numbers and input/outfile and I just can't seem to figure it out. Any help is well appreciated as I need to complete this asap. Thank you.

If you read the sticky posts in this forum, you'll see we don't do your work for you. Please show the work you've done so far, and then we'll help point you in the right direction.

I actually found this site while trying to fix my awful coding so no, I did not have a chance to read the site's stickies and for that, I apologize. I've been trying to figure this out for the past three hours and I know this is pretty simple but I just started on my own last week. I took out the coding for the in/out file as it was just causing a headache(sintax errors).

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

using namespace std;

int main() 
{ 
    srand((unsigned)time(0)); 
    int random_integer; 
    for(int index=0; index<5; index++){ 
        random_integer = (rand()%55)+1; 
        cout << random_integer << endl;
	}
		
		system ("pause");
}

I have my first five random numbers down but the sixth is where I'm confused as it involves a different range 1-42. I'm not sure how to incorporate the in/output coding either. "Starting out with C++" by Tony Gaddis is kind of brief on those functions...

I actually found this site while trying to fix my awful coding so no, I did not have a chance to read the site's stickies and for that, I apologize. I've been trying to figure this out for the past three hours and I know this is pretty simple but I just started on my own last week. I took out the coding for the in/out file as it was just causing a headache(sintax errors).

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

using namespace std;

int main() 
{ 
    srand((unsigned)time(0)); 
    int random_integer; 
    for(int index=0; index<5; index++){ 
        random_integer = (rand()%55)+1; 
        cout << random_integer << endl;
	}
		
		system ("pause");
}

I have my first five random numbers down but the sixth is where I'm confused as it involves a different range 1-42. I'm not sure how to incorporate the in/output coding either. "Starting out with C++" by Tony Gaddis is kind of brief on those functions...

Perhaps add another two lines of code after the 'for' loop?

random_integer = (rand()%42)+1; 
        cout << random_integer << endl;

I was up all night and finally figured it out. Although the code doesn't look so pretty and it's some what longer then needed, it works. Thanks for the response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.