c++ help
okay i have got this small problem: i'm doing a program that you can enter numbers in and it will give out the hertz and length and the sound. im using Beep(hertz,length); but im not able to get it so that you can enter the numbers from the prog here is the code
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int hertz;
int length;
void beep(){
cout<<"Enter the hertz of the sound : ";
cin>>hertz;
cin.get();
system("CLS");
cout<<"Enter the length of the sound ( ms ) : ";
cin>>length;
cin.get();
system("CLS");
cout<<"This sound is "<<hertz<<" hz and "<<length<<"ms long";
Beep(" "<<hertz<<" ", " "<<length<<" ");
}
int main(int argc, char *argv[])
{
beep();
cout<<"lol";
cin.get();
}
and if you try it it won't work.. i have tryed to get it with stings like
and i was using #string and string hertz; string length; when i tryed it i can't get it … help me? :p
#include <cstdlib> #include <iostream> #include <string> #include <windows.h>
using namespace std;
int hertz; int length; void beep(){ cout<<"Enter the hertz of the sound : "; cin>>hertz; cin.get(); system("CLS"; cout<<"Enter the length of the sound ( ms ) : "; cin>>length; cin.get(); system("CLS"; cout<<"This sound is "<<hertz<<" hz and "<<length<<"ms long"; Beep(" "<<hertz<<" ", " "<<length<<" ";
} int main(int argc, char *argv[]) { beep(); cout<<"lol"; cin.get(); }
Okay, now i wont promise these are your problems, but a few things i see that may be the source of the problem…
Beep(" "<<hertz<<" ", " "<<length<<" "; probably should be Bee(hertz,length);
not sure why you are using cin.get() after using cin >> heartz and cin > length
those may be the problems… iunno tho. dont have a c++ compiler on this box .
i don't have a c++ compiler on my laptop so i can't test it but logicaly this is your prog:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int hertz;
int length;
void beep(){
cout<<"Enter the hertz of the sound : ";
cin>>hertz;
system("CLS");
cout<<"Enter the length of the sound ( ms ) : ";
cin>>length;
system("CLS");
cout<<"This sound is "<<hertz<<" hz and "<<length<<"ms long";
Beep(hertz,lenght);
}
int main(int argc, char *argv[])
{
beep();
cout<<"lol";
cin.get();
}```