0

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");*/
};
  • You put a semicolon at the end of the `main()` function, not at the end of the class declaration. – Wyzard Nov 01 '12 at 01:10
  • 1
    Also, the call to `void checkout();` within `main()` is not syntactically valid. First, because you don't write the return type (`void` in this case) when you call a function, and second, because `checkout()` is a member function, not a standalone function, so you have to call it on an object that's an instance of the `operations` class. – Wyzard Nov 01 '12 at 01:12
  • i'm still getting the error.it says its at line 39, but my program only has 38 lines – user1504257 Nov 01 '12 at 01:12

3 Answers3

2
  1. Your class definition needs a trailing semi-colon, not your main function.

    class operations{
        void checkout(){
            cout << "Check out here!!";
        }
    };
    
  2. "void main" is wrong. main always returns int.

animuson
  • 53,861
  • 28
  • 137
  • 147
Joe
  • 41,484
  • 20
  • 104
  • 125
0

This is your code, corrected as I interpreted what you wanted to perform.

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

class operations
{
    public:void checkout()
    {
        cout << "Check out here!!";
    }
};

int main()
{
    string item;
    int choice;
    operations op;

    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)
    {
        op.checkout();
    }

    return 0;
}

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 right void checkout() you have to instatiate an object of type operations and then call its method with op.checkout()

Last, always declare int main() and place return 0 if 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() implementation

void checkout()
{
    cout << "Check out here!!";
}

so that you can call them simply with

checkout()
unziberla
  • 545
  • 4
  • 22
-2

I think you should add this in the top of your file(make this the first line):

#include "stdafx.h"
shengy
  • 9,461
  • 4
  • 37
  • 61