Hello everyone,
I have been visiting this site often as a guest, and I've noticed that it is a very nice community. Now, I have a question myself, and I hope I will be able to get some answers =D
Anyways, I started learning C++ about... 2-3 weeks ago. Not visual C++, although I am going to start that soon. Anyways, there is this school project (not a tech project, a physics project). I wanted to write a program, so it's easier for me to present and everything. I am stuck because I want to print some numbers to notepad, but printf is too limited for this and I don't think it can be used... (I may very well be wrong, so prove me wrong here if you can =D)
Here is my code so far:
(using Devc++)
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;
#define PI=3.14159265358979323846264338327950
int main ()
{
double n;
string string;
double t;
int time; // in ms
char note;
int freq;
double sinwave;
double envelope1;
double envelope2;
double envelope;
double result;
int amp=20500;
int b=65;
int c=1.5;
int k=1.85;
cout << "Please enter the note you would like to have played. 1 character only.\n"
<< "Or, select from the list below:\n\n"
<< "U) C sharp;\n"
<< "V) E flat;\n"
<< "W) G flat;\n"
<< "Y) A flat;\n"
<< "Z) B flat;\n\n"
<< "X) Exit;\n\n";
cin >> note;
if (note == 'a' || note == 'A'){
freq = 440;}
else if (note == 'b' || note == 'B'){
freq = 494;}
else if (note == 'c' || note == 'C'){
freq = 262;}
else if (note == 'd' || note == 'D'){
freq = 294;}
else if (note == 'e' || note == 'E'){
freq = 330;}
else if (note == 'f' || note == 'F'){
freq = 349;}
else if (note == 'g' || note == 'G'){
freq = 392;}
else if (note == 'u' || note == 'U'){
freq = 277;}
else if (note == 'v' || note == 'V'){
freq = 311;}
else if (note == 'w' || note == 'W'){
freq = 370;}
else if (note == 'y' || note == 'Y'){
freq = 415;}
else if (note == 'z' || note == 'Z'){
freq = 466;}
else if (note == 'x' || note == 'X'){
goto Exit;}
cout << "/n/nPlease enter the amount of time the note lasts.\n"
<< "Please enter it in milliseconds (ms).\n";
getline (cin, string);
stringstream(string) >> time;
for (t=0, t<(44.1*time), t+(1/44100){
sinwave = amp*SIN(2*PI*freq*t);
envelope1 = b*t;
envelope2 = c*EXP(-k*t);
if (envelope1<envelope2){
envelope = envelope1)}
else{
envelope = envelope2)}
result = sinwave*envelope;
Exit:
return 0;
}
don't worry if you don't understand any of the physics. hopefully those will work out, but I can't really test them right now.
anyways, after all of this I end up with this double number "Result". I want to be able to print this number Result, all by itself, into a notepad, start a new line in notepad, and have the for loop all over again.
How is this possible? (and if you want you can clean up some other parts of my code too :O)
Thank you guys very much!