Mar 8, 2013 at 12:56am UTC
I have to write out to a text file using a for loop. The file is being created, but there is no data in the file when I open it. Here's what I've got (assuming f1=10, f2=10, and samperiod = .025)
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
....
....
....
void GenerateTone (double f1, double f2, double dur, double samperiod)
{
double tone;
ofstream outfile;
outfile.open("OutputTone.txt");
for (dur = 0; dur >= .5; dur = dur + samperiod)
{
tone = (sin(2*M_PI*f1*dur))+(sin(2*M_PI*f2*dur));
outfile << dur << " " << tone << endl;
}
outfile.close();
}
I'm not sure what the problem is, maybe something with the sin()?
Thanks!
Mar 8, 2013 at 12:59am UTC
It's your loop. You initialise dur to zero then tell the loop to run while dur is greater or equal to 0.5. Therefore, the loop never runs.