Hi everybody I've been suffering from this very annoying issue I was hoping someone might be able to help me resolve here. I've created a program that generates a 1 dimensional random walk for a "particle" starting at a position zero, with a step size and a bound for the random walk which the user can decide via their input (hence the particle "falls off the ledge" when reaching the bound, e.g. of size 500 if it goes beyond 500 or -500).
I've been able to get a series that spits out the data tracking the location of the particle with each iteration printed on the terminal using the cout command. However, when I tried to make it output to an Excel CSV I got an error saying
"error: invalid operands of type 'int'and '<unresolved overloaded function type>' to binary 'operator<<'"
#include<iostream>
#include <stdio.h>
#include <cstdlib>
#include <time.h>
#include <fstream>
usingnamespace std;
int main()
{
cout<<"\nWelcome to the random walk!"<<endl;
int a;
int b;
int t;
t=time(NULL);
int t0;
int tm;
t0=t;
srand(time(NULL));
cout<<"The time today is: ";
cout<<t<<endl;
cout<<"Yo dawg! Give me the step witdth for the random walk: "<<endl;
cin>>a;
cout<<"Dude! What's the width of the plank? "<<endl;
cin>>b;
int s;
int r;
s=0;
ofstream MyExcelFile;
MyExcelFile.open("example.csv");
while (s*s<b*b)
{
tm=t-t0;
cout<< s << " | " << tm << endl;
MyExcelFile << s,tm << endl;
r=(rand()%10)+1;
if (r>5)
{
s=s+a;
}
else
{
s=s-a;
}
t++;
}
MyExcelFile.close();
}
Could someone help me identify the problem here, and what I need to change to correct this?
Hi guys, thanks so much for the help. It turns out putting double inverted commas round the comma in the line where the output is to MyExcelFile solved the problem.
It therefore now reads: MyExcelFile << s << "," << tm << endl;