Thread: Not compiling, errors are

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    69

    Not compiling, errors are

    goNot compiling, errors are-screenshot-2021-08-03-100119-jpg



    Code:
    #include <iostream>#include <fstream>
    #include <iomanip>
    #include <string>
    #include <cstdlib>
    using namespace std;
    
    
    enum class RequestType {
    	ZERO BALANCE = 1, CREDIT_BALANCE, DEBIT_BALANCE, END
    };
    
    
    RequestType getRequest();
    bool shouldDisplay(RequestType, double);
    void outputLine(int, const string&, double);
    
    
    int main() {
    
    
    	ifstream inClientFile{ "clients.txt", ios::in };
    
    
    	if (!inClientFile) {
    		cerr << "File could not be opened" << endl;
    		exit(EXIT_FAILURE);
    	}
    	
    	RequestType  request{getRequest()};
    
    
    	while (request != ResquestType::END) {
    		switch (request) {
    		case RequestType::ZERO_BALANCE:
    			cout << "\nAccounts with zero balance:\n";
    			break;
    		case RequestType::CREDIT_BALANCE;
    				cout << "\nAccounts with credit balances:\n";
    				break;
    		case RequestType::DEBIT_BALANCE:
    			cout << "\nAccounts with debit balances:\n";
    			break;
    
    
    		}
    
    
    		int account;
    		string name;
    		double balance;
    
    
    		inClientFile >> account >> name >> balance;
    
    
    		while (!inClientFile.eof()) {
    
    
    			if (shouldDisplay(request, balance)) {
    				outputLine(account, name, balance);
    			}
    			inClientFile >> account >> name >> balance;
    		}
    
    
    		inClientFile.clear();
    		inClientFile.seekg(0);
    		request = getRequest();
    	}
    
    
    	cout << "End of run." << endl;
    
    
    }
    
    
    RequestType getRequest() {
    	cout << "\nEnter request\n"
    		<< " 1 - List accounts with zero balances\n"
    		<< " 2 - List accounts with credit balances\n"
    		<< " 3 - List accounts with debit balances\n"
    		<< " 4 - End of run" << fixed << showpoint;
    	int type;
    
    
    	do {
    		cout << "\n?  ";
    		cin >> type;
    
    
    	} while (type < static_cast<int>(RequestType::ZERO_BALANCE) || type > static_cast<int>(RequestType::END));
    
    
    	return static_cast<RequestType>(type);
    
    
    }
    
    
    bool shouldDisplay(RequestType type, double balance) {
    	if (type == RequestType::ZERO_BALANCE && balance == 0) {
    		return true;
    	}
    
    
    	if (type == RequestType::CREDIT_BALANCE && balance < 0) {
    		return true;
    	}
    
    
    	if (type == RequestType::DEBIT_BALANCE && balance > 0) {
    		return true;
    	}
    
    
    	return false;
    }
    
    
    void outputLine(int account, const string&& name, double balance) {
    	cout << left  << setw(10)  << account  << setw(13)  << name << setw(7)  << setprecision(2)  << right  << balance  << endl
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,611
    You have a lot of misspellings, and typos, incorrect statement terminations, etc.

    For example that first error is being caused by a possible missing underscore.

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    I fixed the misspellings and placed the missing underscore. Now I get:

    Not compiling, errors are-screenshot-2021-08-03-110505-jpg
    Quote Originally Posted by jimblumberg View Post
    You have a lot of misspellings, and typos, incorrect statement terminations, etc.

    For example that first error is being caused by a possible missing underscore.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,611
    Please repost your code. Several of the error messages tell you what to look for "expected ':' before ';' on the given line.

    Also in future cut and paste the error messages into a post, pictures can be hard to read, especially on small format devices.

  5. #5
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by jimblumberg View Post
    Please repost your code. Several of the error messages tell you what to look for "expected ':' before ';' on the given line.

    Also in future cut and paste the error messages into a post, pictures can be hard to read, especially on small format devices.
    Ok.

    Code:
    #include <iostream>#include <fstream>
    #include <iomanip>
    #include <string>
    #include <cstdlib>
    using namespace std;
    
    
    enum class RequestType {
    	ZERO_BALANCE = 1, CREDIT_BALANCE, DEBIT_BALANCE, END
    };
    
    
    RequestType getRequest();
    bool shouldDisplay(RequestType, double);
    void outputLine(int, const string&, double);
    
    
    int main() {
    
    
    	ifstream inClientFile{ "clients.txt", ios::in };
    
    
    	if (!inClientFile) {
    		cerr << "File could not be opened" << endl;
    		exit(EXIT_FAILURE);
    	}
    
    
    	RequestType  request{getRequest()};
    
    
    	while (request != RequestType::END) {
    		switch (request) {
    		case RequestType::ZERO_BALANCE::
    			cout << "\nAccounts with zero balance:\n";
    			break;
    		case RequestType::CREDIT_BALANCE;
    				cout << "\nAccounts with credit balances:\n";
    				break;
    		case RequestType::DEBIT_BALANCE:
    			cout << "\nAccounts with debit balances:\n";
    			break;
    
    
    		}
    
    
    		int account;
    		string name;
    		double balance;
    
    
    		inClientFile >> account >> name >> balance;
    
    
    		while (!inClientFile.eof()) {
    
    
    			if (shouldDisplay(request, balance)) {
    				outputLine(account, name, balance);
    			}
    			inClientFile >> account >> name >> balance;
    		}
    
    
    		inClientFile.clear();
    		inClientFile.seekg(0);
    		request = getRequest();
    	}
    
    
    	cout << "End of run." << endl;
    
    
    }
    
    
    RequestType getRequest() {
    	cout << "\nEnter request\n"
    		<< " 1 - List accounts with zero balances\n"
    		<< " 2 - List accounts with credit balances\n"
    		<< " 3 - List accounts with debit balances\n"
    		<< " 4 - End of run" << fixed << showpoint;
    	int type;
    
    
    	do {
    		cout << "\n?  ";
    		cin >> type;
    
    
    	} while (type < static_cast<int>(RequestType::ZERO_BALANCE) || type > static_cast<int>(RequestType::END));
    
    
    	return static_cast<RequestType>(type);
    
    
    }
    
    
    bool shouldDisplay(RequestType type, double balance) {
    	if (type == RequestType::ZERO_BALANCE && balance == 0) {
    		return true;
    	}
    
    
    	if (type == RequestType::CREDIT_BALANCE && balance < 0) {
    		return true;
    	}
    
    
    	if (type == RequestType::DEBIT_BALANCE && balance > 0) {
    		return true;
    	}
    
    
    	return false;
    }
    
    
    void outputLine(int account, const string&& name, double balance) {
    	cout << left  << setw(10)  << account  << setw(13)  << name << setw(7)  << setprecision(2)  << right  << balance  << endl;
    }

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,611
    What character is expected at the end of a case clause?

    Look closely at the lines referenced in your error messages.

    Do you know the different usage/meaning of the "::" sequence?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,796
    > case RequestType::ZERO_BALANCE::
    This should be one :

    > case RequestType::CREDIT_BALANCE;
    This one should be one : as well.

    > while (!inClientFile.eof())
    This you can simplify with
    Code:
            while (inClientFile >> account >> name >> balance) {
                 if (shouldDisplay(request, balance)) {
                    outputLine(account, name, balance);
                }
                inClientFile >> account >> name >> balance;
            }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by jimblumberg View Post
    What character is expected at the end of a case clause?

    Look closely at the lines referenced in your error messages.

    Do you know the different usage/meaning of the "::" sequence?
    Wow, I have the worse eyesight imaginable. The :: means like a term being associated with another term?

  9. #9
    Registered User
    Join Date
    Sep 2020
    Posts
    84
    :: is called the scope resolution operator.

    More details here: https://stackoverflow.com/questions/15649580/using-in-c

  10. #10
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    There's that, but in the scope I was using it. I was calling a class of a function with code already written. So that it could be later used without having to write all the same code again...
    Quote Originally Posted by thmm View Post
    :: is called the scope resolution operator.

    More details here: function - Using :: in C++ - Stack Overflow

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    4,611
    There's that, but in the scope I was using it. I was calling a class of a function with code already written. So that it could be later used without having to write all the same code again...
    No, in the scope you are misusing the scope resolution operator the compiler thinks that ZERO_BALANCE is either a namespace, class or enumeration, hence the error message.

    Remember that C++ is very lax about whitespace, what the compiler is probably seeing is something more like:
    Code:
             case RequestType::ZERO_BALANCE::cout << "\nAccounts with zero balance:\n";
    Which is probably not what you expect.

    Look at the error messages:
    Code:
    main.cpp|36|error: ‘RequestType::ZERO_BALANCE’ is not a class, namespace, or enumeration|
    main.cpp|36|error: expected ‘:’ before ‘;’ token
    Notice that there are no semicolons ';' on line 36, the next semicolon is at the end of line 37.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with errors in compiling
    By m-kosier in forum C Programming
    Replies: 5
    Last Post: 11-29-2011, 06:31 PM
  2. Need Help in Compiling errors
    By sick in forum C Programming
    Replies: 2
    Last Post: 01-21-2010, 03:26 AM
  3. Compiling errors
    By courtesan in forum C Programming
    Replies: 2
    Last Post: 08-18-2005, 10:52 AM
  4. c++ compiling errors... very odd!
    By renderstream in forum C++ Programming
    Replies: 9
    Last Post: 03-07-2004, 05:39 PM
  5. Compiling errors again
    By Jessica in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2002, 09:47 AM

Tags for this Thread