Question: C++, help me edit use using namespace std; please edit and modify my code to look bit betetr Accepts three command-line arguments: COUNT, MIN, and

C++, help me edit

use using namespace std;

please edit and modify my code to look bit betetr

Accepts three command-line arguments: COUNT, MIN, and MAX, where COUNT is the number of random numbers to generate, and MIN and MAX specify the range of the generated numbers.

Generates COUNT random numbers between MIN and MAX (inclusive) and writes them to a file called numbers.dat.

My Code

#include

#include

#include

int main(int argc, char *argv[]) {

if (argc != 4) {

std::cerr << "Usage: generate COUNT MIN MAX" << std::endl;

return 1;

}

int count = std::stoi(argv[1]);

int min = std::stoi(argv[2]);

int max = std::stoi(argv[3]);

std::ofstream out("numbers.dat");

for (int i = 0; i < count; i++) {

int num = (rand() % (max - min + 1)) + min;

out << num << std::endl;

}

out.close();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!