I am trying to add command line arguments to my programs. So I was experimenting and cannot figure out this intellisense warning for the life of me. It keeps on saying it is expecting a ')', but I don’t have any idea why.
Here is the code it does not like:
// Calculate average
average = sum / (argc – 1);
Then it underlines the subtraction operator. Below is the full program.
#include <iostream>
int main(int argc, char *argv[])
{
float average;
int sum = 0;
// Valid number of arguments?
if (argc > 1)
{
// Loop through the arguments, ignoring the first which is
// the name and path of this program
for (int i = 1; i < argc; i++)
{
// Convert cString to int
sum += atoi(argv[i]);
}
// Calculate average
average = sum / (argc – 1);
std::cout << "\nSum: " << sum << '\n'
<< "Average: " << average << std::endl;
}
else
{
// If an invalid number of arguments, display an error message
// and usage syntax
std::cout << "Error: No arguments\n"
<< "Syntax: command_line [space-delimited numbers]"
<< std::endl;
}
return 0;
}