This code is supposed to do a sum, mean, max, and average function. That part isn't a problem, but I can't get it to compile.
The error message is listed at the bottom. Props to anyone who can fix this quick
Code
#include <iostream>
#include <cstdlib>
int main(int argc, char* argv[]) {
int index=2;
//proper return value
int mainChoice=0;
//Make sure there is an argv[1] to check
if (argc >2) {
//Check the option string
std::string option=std::string(argv[1]);
//create path "mean"
if (option == "mean") {
//declare a variable for the sum
//create a recursive addition to find the sum
int sum=0;
int avg=0;
while (argc>index) {
sum=sum+atoi(argv[index]); //recursively add to the sum
//increase index for recursion
index=index+1;
}
avg=sum/(argc-2); //Take the average
mainChoice=avg;
}
//create path "max"
else if ("max" == option) {
int max=atoi(argv[index]);
//Take the max
while (argc>index) {
//recursively increase the index
index=index+1;
if (atoi(argv[index]) > max) {
max=atoi(argv[index]);
}
}
mainChoice=max;
}
//create path "min"
else if ("min" == option) {
int min=atoi(argv[index]);
//Take the min
while (argc>index) {
//recursively increase the index
index=index+1;
if (atoi(argv[index]) < min) {
min=atoi(argv[index]);
}
}
mainChoice=min;
}
//create path "sum"
else if ("sum" == option) {
int sum=atoi(argv[index]);
while ((argc-1)>index) {
index=index+1;
sum=sum+atoi(argv[index]);
}
mainChoice=sum;
}
else {
return 1;
}
else if (2 > argc) {
//proper return value
return 2;
}
else if (2 == argc) {
//proper return value
return 3;
}
}
//display main message
std::cout<<mainChoice;
//Return 0 if everything ran successfully
return 0;
}
//84:2: error: 'cout' in namespace 'std' does not name a type
//86:2: error: expected unqualified-id before 'return'
//87:1: error: expected declaration before '}' token
//