converting
May 26, 2015 at 4:23pm UTC
Im getting avgRunsPerSize won't convert it to bool error
error: could not convert ‘avgRunsPerSize’ to ‘bool’
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
#include "griddy.h"
#include "roomba.h"
#include <iostream>
#include <vector>
#include <fstream>
int main()
{
const int rooms=20;
vector<int > avgRunsPerSize; //should probably use a map
Roomba cosmo(0,0,1,1);
for (int i=0; i<rooms; i++)
{
avgRunsPerSize.push_back(cosmo.CleanRoom(1000));
cosmo.room.Resize(i+1, i+1);
}
std::ofstream output("output.txt" );
for (int runs; avgRunsPerSize;)
{
output<<runs<<std::endl;
}
output.close();
return 0;
}
May 26, 2015 at 4:34pm UTC
That for loop makes no sense. The syntax for a for loop is
for (initialisation;repeat while true ;run at the end of every loop)
for example if I wanted a loop that would run 10 times, I would have
for (int i (0); i < 10; ++i)
.
I think what you want is
1 2 3 4
for (int runs (0); runs < rooms;++runs)
{
output<<avgRunsPerSize[runs]<<std::endl;
}
May 26, 2015 at 6:38pm UTC
Or, if you're trying to use the ranged for loop:
1 2
for (int runs: avgRunsPerSize)
output << runs << '\n' ;
Note that using
std::endl here is probably not appropriate. You don't need the stream flushed every iteration of the loop.
Topic archived. No new replies allowed.