Problem calling functions??

This program in not completed. I am creating a large program in order to calculate a company's weekly payroll. For now I am filling in the separate functions piece by piece before the rest of the program is completed.

Right now I am trying to use separate functions to call other functions. I need to ask the user for the file name and then open the file.

I am no longer getting any compiler errors however when I run the program all it displays is "Welcome."

So it's not actually calling the NameTheFile function and the OpenTheFile function. It just says "Welcome" and then closes down.

Why is it doing this?

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void NametheFile()
{

ifstream inputFile;
string filename;

//Asks user for file name.

cout << "What is the file name?\n.";
cin  >> filename;
void OpenTheFile();

}

void OpenTheFile()
{

ifstream inputFile;
string filename;
char letter;
int number;

//Opens the file
inputFile.open(filename.c_str());

if (inputFile)
{
    while (inputFile >> letter)
    {
        cout << "File opened successfully.\n";
        cout << letter << endl;
    }

    //CLOSES THE FILE. (remove)
    inputFile.close();
}
else
    {
        //Error checking
        cout << "Error opening the file.\n";
    }
}

void GetTheData()
{
    //statement
    //statement
    //statement
}

void CalculateTheTotalPay()
{

    //statement
    //statement
    //statement
}

void PrintTheData()
{
    //statement
    //statement
    //statement
}

int main()
{
    //Main to call other functions
    cout << "Welcome.\n";
    void NameTheFile();

    return 0;

}
Line 77: you are not calling function here. You are declaring function with the name "NameTheFile" which takes no parameters and does not return anything.

Turn compiler warnings on, they should warn you about it.

To call function, you should write function name followed by function call operator, like that:
1
2
              foo();
//function name↑  ↑function call operator 
Topic archived. No new replies allowed.