Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions