Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

c++ help


ghost's Avatar
0 0

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


ghost's Avatar
0 0

well, if youre trying to use winkey-faced emoticons in your code….that might be your problem :]


reaper4334's Avatar
Member
0 0

Okay, try disabling smileys in your post so we can read it easier…

Then tell us what error you get? It not working isn't too specific, but if you can give the error… you might get help easier.

Reaper


ghost's Avatar
0 0

#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 .


ghost's Avatar
0 0

i don't have a c++ compiler on my laptop so i can't test it but logicaly this is your prog:

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;

using namespace std;

int hertz;
int length;
void beep(){
cout&lt;&lt;&quot;Enter the hertz of the sound : &quot;;
cin&gt;&gt;hertz;
system(&quot;CLS&quot;);
cout&lt;&lt;&quot;Enter the length of the sound ( ms ) : &quot;;
cin&gt;&gt;length;
system(&quot;CLS&quot;);
cout&lt;&lt;&quot;This sound is &quot;&lt;&lt;hertz&lt;&lt;&quot; hz and &quot;&lt;&lt;length&lt;&lt;&quot;ms long&quot;;
Beep(hertz,lenght);




}
int main(int argc, char *argv[])
{
beep();
cout&lt;&lt;&quot;lol&quot;;
cin.get();
}```

ghost's Avatar
0 0

it looks like you applied my fix to Beep, did you change anything else?


ghost's Avatar
0 0

i eliminated the cin.get()

and also depend on the compiler the header section need to be changed some of them no longer have the c<name of the lib here>

so the headers can looks like this:

#include &lt;iostream&gt;
#include &lt;string.h&gt;
#include &lt;windows.h&gt;

beep() etc ```

ghost's Avatar
0 0

righto… so we are on the same page. i'll be interested to see if it fixes it


ghost's Avatar
0 0

thank you only_samurai it worked out with you help drOptix: the problem wasn't that i wouldn't get the string to work without ".h" but it didnt work in Beep but with cout<<("lololol"+hertz.c_str()); it did work but ty anyway :D