cannot convert char** to char*

On line 43 I am getting the error "cannot convert char** to char*. I don't quite understand why. Is it an issue with the use of 'atoi'?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;

const double DEATH_RATE = 0.1;

const double CONVERSION_RATE = 0.00001;

const double GROWTH_RATE = 0.4;

const double WOLF_ABILITY = 0.0005;

const int CAPACITY = 30000;

const int YEARS = 100;

const int TABLE_INCREMENT = 10;

void validate(int[], int[], int, char[]);
void populate(int[], int[]);
void computeMinimum(int[], int&);
void computeMaximum(int[], int&);
void writeOut(ofstream&, int, int, int, int, int[], int[]);


int main(int argc, char *argv[])
{
    int wolfMax = 0;
    int wolfMin = 0;
    int mooseMax = 0;
    int mooseMin = 0;

    int wolves[101] = {0};
    int moose[101] = {0};
    moose[0] = 100;
    wolves[0] = 10000;
    ofstream report;
    report.open("report.txt");
    cout << argv[1];

    validate(moose, wolves, argc, argv);
    populate(wolves, moose);
    computeMinimum(wolves, wolfMin);
    computeMaximum(wolves, wolfMax);
    computeMinimum(moose, mooseMin);
    computeMaximum(moose, mooseMax);
    writeOut(report, wolfMin, wolfMax, mooseMin, mooseMax, wolves, moose);

    return 0;
}

void computeMaximum(int data[], int& q)
{
    int comp = data[0];
    for(int k = 1; k < YEARS; k++)
    {
        if(comp < data[k])
        {
            comp = data[k];
            q = k;
        }
    }
}

void computeMinimum(int data[], int& p)
{
    int comp = data[0];
    for(int j = 1; j < YEARS; j++)
    {
        if(comp > data[j])
        {
            comp = data[j];
            p = j;
        }
    }
}

void populate(int wolves[], int moose[])
{


    for(int i = 1; i < YEARS; i++)
    {
        wolves[i] = ((1 - DEATH_RATE + CONVERSION_RATE * moose[i - 1]) * wolves[i -1]);
        moose[i] = (1 + GROWTH_RATE - (GROWTH_RATE * moose[i - 1]) / (CAPACITY - WOLF_ABILITY * wolves[i - 1]) * moose[i - 1]);
    }

}

void validate(int moose[], int wolves[], int argc, char *argv[])
{
    if(argc == 3)
    {
        wolves[0] = atoi(argv[1]);
        moose[0] = atoi(argv[2]);
    }
}

void writeOut(ofstream& report, int wolfMin, int wolfMax, int mooseMin, int mooseMax, int wolves[], int moose[])
{
    report << "----------" << "Year" << "----------" << "Wolf" << "----------" << "Moose" << endl;
    for(int k = 0; k < YEARS; k += TABLE_INCREMENT)
    {
        report << setw(15) << k << wolves[k] << moose[k] << endl;
    }
    report << "The minimum population for wolves was" << wolves[wolfMin] << "in year" << wolfMin;
    report << "The maximum population for wolves was" << wolves[wolfMax] << "in year" << wolfMax;
    report << "The minimum population for moose was" << moose[mooseMin] << "in year" << mooseMin;
    report << "The minimum population for wolves was" << moose[mooseMax] << "in year" << mooseMax;
}
Looking at your function prototype, it appears that it expects a single C-string not an array of C-string for the final argument.

By the way what does line 43 have to do with atoi()?
Thanks. I guess I thought the issue might have been converting argv to an integer.
Topic archived. No new replies allowed.