Things you could improve:
Bugs
- Your initial printing of the input command line arguments looks buggy.
cout<<argv[1]<<endl; cout<<argv[2]<<endl; cout<<argv[2]<<endl;
It looks like you meant to print argv[3]
here, but accidentally put a 2
.
Syntax/Styling
Please don't use
using namespace std;
. It's considered a bad practiceIt's considered a bad practice, and is a bad habit to form.Use
std::isdigit()
instead of yourisnum()
function.You don't need to include the
<cstdlib>
or<string>
headers (you will have to include<string>
if you implementstd::isdigit()
).Put the variable declarations to separate lines.
double start,end,step_size;
From Code Complete, 2d Edition, p. 759:
With statements on their own lines, the code reads from top to bottom, instead of top to bottom and left to right. When you’re looking for a specific line of code, your eye should be able to follow the left margin of the code. It shouldn’t have to dip into each and every line just because a single line might contain two statements.
Loops
- You could use more loops throughout your program.
if(isnum(argv[1]) && isnum(argv[2]) && isnum(argv[3])) { cout<<argv[1]<<endl; cout<<argv[2]<<endl; cout<<argv[2]<<endl; ...
Using a simple for
loop here to reduce the code down a bit.
for (int i = 0; i < 3; i++)
{
if (std::isdigit(*argv[i])) std::cout << argv[i] << std::endl;
else return -1; // or re-ask for user input
}