primary expression error.. please help..

Please help me. I'm stuck. The coding seems ok. I'm using external file which is displaymenu.cpp and the main is another file. so included it in the main file. I really don't know whats the problem here. the coding all seems okay.

Cracking my head. Please help:(

This is the external file. Displaymenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
using namespace std;

void displaymenu()
{
     
     cout<<"ABC Gas Station System"<<endl;
     cout<<"1.	Pump petrol"<<endl;
     cout<<"2.	Fuel report"<<endl;
     cout<<"3.	Dispenser report"<<endl;
     cout<<"4.	Summary report"<<endl;
     cout<<"5.	Quit"<<endl;
     cout<<"Which operation (1, 2, 3, 4 or 5)?:"<<endl;
}


and the main.cpp is 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
82
#include "displaymenu.cpp"
#include<iostream>
using namespace std;
void PumpPetrol();
int main(){
    
           int choice;
           char option='y';
           string answer;
           char fuel_type;
           float fuel_amount;
           float Litre;

           answer = "Yes";

           while ( answer[0] == 'Y' || answer[0] == 'y' ) {
           
           displaymenu();
           
           cin>>choice;
           
           switch(choice)
           {
                 case 1:   PumpPetrol();
                           break;
                 case 2: //FuelReport();
                           break;
                 case 3: //DispenserReport();
                           break;
                 case 4: //SummaryReport();
                           break;
                 case 5: cout<<"Thanks for using the sytem";
                           break;
                 default: cout<<"Invalid";
                           break;
                             
                }
           
void PumpPetrol(){
       
       cout<<"Enter Fuel type(S=Super,V=V-Power,D=Diesel:";
       cin>>fuel_type;
       cout<<"Enter Fuel amount:";
       cin>>fuel_amount;
    
       switch (fuel_type)
{
       case's':case'S':
       cout<<"Super";
       Litre=fuel_amount*100/188;
       cout<<"Amount:"<<fuel_amount<<endl;
       cout<<"Litre:"<<Litre<<endl;
       break;
    
       case'v':case'V':
       cout<<"V-Power";
       Litre=fuel_amount*100/192;
       cout<<"Amount:"<<fuel_amount<<endl;
       cout<<"Litre:"<<Litre<<endl;
       break;
    
       case'd':case'D':
       cout<<"Diesel";
       Litre=fuel_amount*100/158;
       cout<<"Amount:"<<fuel_amount<<endl;
         cout<<"Litre:"<<Litre<<endl;
       break;
    
       default:
         cout<<"Invalid";
         break;
         
        
        }  
         
            cout << "Do you want to continue (Y/N)? ";
            cin >> answer;
               
            system("pause");
            
           
}} }




PLEASE HELP!!
Help is much appreciated

The complier error is
1) In function `int main()':
2) expected primary-expression before "void" -- line 39 on main.cpp
3) expected `;' before "void" -- line 39 on main.cpp
Last edited on
Firstly, please edit your post so it uses code tags - select the code then press the <> button on the right

Do you have a compile error? If so post the full compiler output.
The IdeasMan

thanks for your reply.
I have re-edited my post.

Hope someone would help me out on this. thanks alot.

Thanks for editing your post.

You have two misplaced close braces.
Function main is missing a close brace.
main's while loop is missing a close brace.
These must be before the function PumpPetrol.
The two braces at line 82 belong at line 38.
You can't embed function PumpPetrol inside your main function.

Last edited on
Your problem is that you don't have a .h (header) file for "Displaymenu.cpp" , I'd recomend you create a .h file and Call it "Displaymenu.h" and include it in both "Displaymenu.cpp" and "main.cpp" then create a function signature of displaymenu() by adding void displaymenu(); to "Displaymenu.h" and that should solve your problem.
Here's some thoughts:

You could just declare the dsiplaymenu function in main with an extern keyord - remembering to still compile with displaymenu.cpp and main.cpp. This is the easiest thing to do for this practice example.

Header files are for the declaration of functions or classes. .cpp files contain the code that implements the functions, and they include any header file that is needed in that file. Seen as there is only one function, making a header file isn't worth it. But that is the normal method when there are a group of functions.

If one is using classes, then the declaration goes in the header file, the code for the functions in the .cpp file, and main.cpp or any other .cpp file that needs it, will include the header file.

One should never include a .cpp file.

Hope all goes well.
Topic archived. No new replies allowed.