functions

Can someone please tell me why my void function will not work? It is supposed to read out the message.

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

void display();

// begin main Function Definition
int main()
{

return 0;
} //end of main function.

void display()

{

cout << "Assignment 5b\n"
<< "Programmed by Rodger Coleman\n\n";

}
You may want to actually call the function from main()

1
2
3
4
5
6
int main()
{
    display();

    return 0;
} //end of main function. 
Your void function works just fine - when it is called! main() doesn't do anything and just returns. In c/C++ main() is the function that is executed when the program is run.

PS When posting code please use code tags so that the code is readable!

[code]
// the code goes here
[/code]

Last edited on
https://www.learncpp.com/cpp-tutorial/introduction-to-functions/

And...this is not the first time I've mentioned this....
LEARN to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either

Why do you deliberately REFUSE to use code tags even after being asked to use them before now?
Given you other topics, it's astonishing that you ask such a question. Everyone has to start somewhere, but really?
Putting all that together we get the following. That took about 2 minutes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

void display();

// begin main Function Definition
int main()
{
    display();
    return 0;
} //end of main function.

void display()
{
    cout << "Assignment 5b\n"
    << "Programmed by Rodger Coleman\n\n";
}



Assignment 5b
Programmed by Rodger Coleman

Program ended with exit code: 0
Topic archived. No new replies allowed.