calling functions and other stuff

I know you can call functions to bring up new code at a particular point in a program. I was told you can call sound files such as sound.mp3 and also picture files like picture.jpg, is this right? and how would you call such a thing into a program?
(lines 21 && 44)and then some picture at the end of the program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include <iostream>
#include <iomanip>
using namespace std; 

int main() 
{
string item;
double wholeSale;
double markup;
double total;

double calculateRetail( double, double); // function prototype

cout << "Input an item for sale.\n";
getline(cin, item);

cout << "Enter the items whole sale price: " << endl;
cin >> wholeSale;

//here i would like to call a sound file that would sound like a amber alert on radio stations, lol.
if( wholeSale < 0 )
{
cout << "ERROR, price of item cannot be less than zero(0)." << endl;
cin >> wholeSale;
}

cout << "Enter items percent of markup: " << endl;
cin >> markup;


if(markup < 0) 
{
cout << "ERROR, Percent values cannot be less than zero(0)." << endl;
cin >> markup;
}

markup = (markup * .01) + 1;

total = calculateRetail(wholeSale, markup); // Function call

cout << fixed << setprecision(2);

//here i would like to output a "cha ching" sound file.
cout << "The retail price for " << item << " is " << total << "." << endl;

system("pause");
return 0;
}

//other function
double calculateRetail( double wholeSale, double markup)
{

double answer;// local varible its scope is only in the function

answer = (wholeSale * markup);

return answer;
}
Last edited on
I would recommend FMOD for sound output. http://www.fmod.org/index.php/download
You would have to download it and then include it in your code. More instructions on how to use it are listed on FMOD's website.
(Also, I did find a webpage with some sample C code that might help you use it quickly: http://stackoverflow.com/questions/428884/how-to-play-mp3-files-in-c )

For image displaying you will need to download a graphics library. I suggest SFML or OpenGL.
http://www.opengl.org/
http://www.sfml-dev.org/

The reason you have to download these libraries is support for sound and images is not directly built into c++. The alternative to downloading libraries would be to write your own.

Hope I helped :)
awesome and nicely said.

so c++ cant just call some sound file like it calls a .txt file, the /a is calling a sound file build into the c++ compiler?
ill read up on what you provided, thanks.
Last edited on
The '\a' sound is not "built-in" to the c++ language. The reason it makes a sound is the computer you are using makes a sound when it receives a beep code. The '\a' outputs a code that most consoles recognize as the system beep code. Just like 'D' is recognized as printing a D or '\n' is recognized as a new line. You can find more character codes here: http://www.asciitable.com/
(Also if you look at character code 07h that is what '\a' represents - the bell/beep code)

C++ does come default with opening filestreams which can be used for .txt and any other file even .mp3.
In fact, if you read through these open source libraries you will eventually find a call to opening a .mp3 filestream, but if you just open a .mp3 file with notepad you will see a lot of random characters. FMOD already has code that knows what to do with those random characters and how to send it to the operating system to make sound.
Last edited on
Topic archived. No new replies allowed.