I keep getting an error: unexpected end-of-file found and i am completely lost. I have checked the curry braces and the parentheses I have put a semicolon at the end of the class I cant figure out whats wrong with it. thanks alot.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class operations{
void checkout(){
cout << "Check out here!!";
}
}
void main(){
string item;
int choice;
cout << "What do you want to do? " << endl;
cout << "Press 1 for checking out " << endl;
cout << "Press 2 for stocking " << endl;
cout << "Press 3 looking at recipts " << endl;
cin >> choice;
cout << choice;
if(choice == 1){
void checkout();
}
/*ofstream myfile;
myfile.open("inventory.txt");
if(myfile.is_open()){
cout << "Enter a grocery item" << endl;
getline(cin,item);
myfile << item;
}
cout << "Your grocery item is " << item;
myfile.close();
system("pause");*/
};
This is your code, corrected as I interpreted what you wanted to perform.
First, note that semicolons are needed after class declarations, and not needed after method declarations
Second, note that
void checkout()in your code would not call the method that you defined in your class, but will instead declare a new method that will simply perform nothing. To call the rightvoid checkout()you have to instatiate an object of typeoperationsand then call its method withop.checkout()Last, always declare
int main()and placereturn 0if the executions flow arrives to the end of your program correctly.As a side note, I would probably not use a class in your program, but simply implement the methods correspondent to the user’s choice before the
main()implementationso that you can call them simply with