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.
#include "displaymenu.cpp"
#include<iostream>
usingnamespace 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
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.
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.
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.