I am having problem with converting and initializing errors. Any help is appreciated. I am a 2 yr Computer Science major, so be gentle.
Here is Code: Sorry its long!
// Kyle Bennett
// CS 318
// Paint Throwing Disturbance
#include <iostream>
#include <iomanip> // set width and decimal
#include <fstream> // use file input and output
#include <cstdlib>
using namespace std;
ofstream outfile;
int zero(float);
int zeroout(int);
float compute(int, float);
float average(float);
void outavg(float);
float myseat(float, int, int);
float bradyseat(float, int, int);
void outmenbrady(int, int, int, int);
int total(int, int);
int success(int, int, int);
void outsucc(int, int);
int main()
{
outfile.open("PaintOut.out"); //open outfile
if (!outfile) // check outfile
{
outfile << "Output file did not open.\n";
return 1;
}
int seats[9][13];
float avg[9][13];
int bags = 40;
int count = 0;
int mr = 0;
int mc = 0;
int ir = 0;
int ic = 0;
zero(avg);
for (int i = 0; i < 100; i++)
{
zeroout(seats);
compute(seats, avg, bags);
}
average(avg);
outavg(avg);
myseat(avg, mr, mc);
bradyseat(avg, ir, ic);
outmenbrady(mr, mc, ir, ic);
total(seats, bags);
for (int i = 0; i < 100; i++)
{
zeroout(seats);
success(seats, bags, count);
}
outsucc(bags, count);
outfile.close();
return 0;
}
int zero(float a[9][13])
{
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
a[i][j] = 0;
}
}
return 0;
}
int zeroout(int a[9][13])
{
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
a[i][j] = 0;
}
}
return 0;
}
int compute(int a[9][13], float b[9][13], int d)
{
for (int i = 0; i < d; i++)
{
int r = rand() % 8 + 1;
int c = rand() % 12 + 1;
a[r][c] = a[r][c] + 2;
if (r != 1)
{
a[(r-1)][c] = a[(r-1)][c] + 1;
}
if (r != 8)
{
a[(r+1)][c] = a[(r+1)][c] + 1;
}
if (c != 1)
{
a[r][(c-1)] = a[r][(c-1)] + 1;
}
if (c != 12)
{
a[r][(c+1)] = a[r][(c+1)] + 1;
}
}
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
b[i][j] = b[i][j] + a[i][j];
}
}
return 0;
}
float average(float a[9][13])
{
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
a[i][j] = a[i][j] / 90.0;
}
}
return 0;
}
void outavg(float a[9][13])
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 13; j++)
{
outfile << setw(5) << a[i][j] << " ";
}
outfile << endl;
}
outfile << endl << endl;
}
float myseat(float a[9][13], int &b, int &c)
{
int temp = a[1][1];
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
if (a[i][j] < temp)
{
temp = a[i][j];
b = i;
c = j;
}
}
}
return 0;
}
float bradyseat(float a[9][13], int &b, int &c)
{
int temp = a[1][1];
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
if (a[i][j] > temp)
{
temp = a[i][j];
b = i;
c = j;
}
}
}
return 0;
}
void outmenbrady(int a, int b, int c, int d)
{
outfile << "I would sit in row " << a << " and column " << b << ".\n";
outfile << "I would put Dr. Brady Rimes in row " << c << " and column " << d << ".\n";
outfile << endl << endl;
}
int total(int a[9][13], int &b)
{
float pct = 0;
int hold = 0;
b = b - 1;
while(pct <= .75)
{
b++;
for (int i = 0; i < b; i++)
{
int r = rand() % 8 + 1;
int c = rand() % 12 + 1;
a[r][c] = a[r][c] + 2;
if (r != 1)
{
a[(r-1)][c] = a[(r-1)][c] + 1;
}
if (r != 8)
{
a[(r+1)][c] = a[(r+1)][c] + 1;
}
if (c != 1)
{
a[r][(c-1)] = a[r][(c-1)] + 1;
}
if (c != 12)
{
a[r][(c+1)] = a[r][(c+1)] + 1;
}
}
for (int i = 0; i < 9; i++)
{
for (int j = 0;j < 13; j++)
{
if (a[i][j] >= 3 || a[i][j] < 5)
{
hold = hold + 1;
}
}
}
pct = hold / 96.0;
}
return 0;
}
int success(int a[9][13], int b, int &d)
{
for (int i = 0; i < b; i++)
{
int r = rand() % 8 + 1;
int c = rand() % 12 + 1;
a[r][c] = a[r][c] + 2;
if (a[r][c] >= 5)
{
i = b;
return 1;
}
if (r != 1)
{
a[(r-1)][c] = a[(r-1)][c] + 1;
}
if (a[(r-1)][c] >= 5)
{
i = b;
return 1;
}
if (r != 8)
{
a[(r+1)][c] = a[(r+1)][c] + 1;
}
if (a[(r+1)][c] >= 5)
{
i = b;
return 1;
}
if (c != 1)
{
a[r][(c-1)] = a[r][(c-1)] + 1;
}
if (a[r][(c-1)] >= 5)
{
i = b;
return 1;
}
if (c != 12)
{
a[r][(c+1)] = a[r][(c+1)] + 1;
}
if (a[r][(c+1)] >= 5)
{
i = b;
return 1;
}
}
for (int i = 1; i < 9; i++)
{
for (int j = 1; j < 13; j++)
{
if (a[i][j] >= 3)
{
d = d + 1;
}
}
}
return 0;
}
void outsucc(int a, int b)
{
outfile << "It takes " << a << " bags to cover 75% of the students with 3 cups of paint, \n";
outfile << "and not drown any students with more than 5 cups of paint.\n\n";
outfile << "With using " << a << " bags there was " << b << " successes out of 100 trails, \n";
outfile << "that still stayed within the constrains.\n";
}
Now here is the error log with line numbers.
||In function 'int main()':|
|46|error: cannot convert 'float (*)[13]' to 'float' for argument '1' to 'int zero(float)'|
|50|error: invalid conversion from 'int (*)[13]' to 'int'|
|50|error: initializing argument 1 of 'int zeroout(int)'|
|51|error: invalid conversion from 'int (*)[13]' to 'int'|
|51|error: cannot convert 'float (*)[13]' to 'float' for argument '2' to 'float compute(int, float)'|
|54|error: cannot convert 'float (*)[13]' to 'float' for argument '1' to 'float average(float)'|
|56|error: cannot convert 'float (*)[13]' to 'float' for argument '1' to 'void outavg(float)'|
|58|error: cannot convert 'float (*)[13]' to 'float' for argument '1' to 'float myseat(float, int, int)'|
|60|error: cannot convert 'float (*)[13]' to 'float' for argument '1' to 'float bradyseat(float, int, int)'|
|64|error: invalid conversion from 'int (*)[13]' to 'int'|
|64|error: initializing argument 1 of 'int total(int, int)'|
|68|error: invalid conversion from 'int (*)[13]' to 'int'|
|68|error: initializing argument 1 of 'int zeroout(int)'|
|69|error: invalid conversion from 'int (*)[13]' to 'int'|
|69|error: initializing argument 1 of 'int success(int, int, int)'|
||=== Build finished: 15 errors, 0 warnings ===|
Please any help would be very appreciative.