fstream fout;
fout.open("data1.txt");
cout << "enter the frequency of the signal" << endl;
cin >> frequency;
cout << "enter the amplitude of the signal" << endl;
cin >> amplitude;
cout << "enter the sampling rate of the signal" << endl;
cin >> samplingrate;
cout << "enter the start time of the signal" << endl;
cin >> starttime;
cout << "enter the end time of the signal" << endl;
cin >> endtime;
time = starttime;
period = 1 / frequency;
for(time = starttime; time <= endtime; time += (1/samplingrate))
{
if (time <= period/2)
{
result = amplitude;
}
else
{
result = (-1)*amplitude;
}
fout << time << " " << result << endl;
cout << result << endl;
}
fout. close();
Even if it did, this would never be true because time can never be greater than period while being less than period/2. (since period/2 is going to be less than period)