Compiler Error Help

This is a discussion on Compiler Error Help within the C++ Programming forums, part of the General Programming Boards category; Hello, basically I have code that when compiled gives me errors that I've tried to fix for a couple of ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    109

    Compiler Error Help

    Hello, basically I have code that when compiled gives me errors that I've tried to fix for a couple of hours and either fix that error and cause another, but i think i'm at the point where its these errors and nothing i'm doing is changing or adding new ones. I'll post my code then the errors, any help is greatly appreciated. Thanks in advance.
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    //this is a struct named Rider that will be used to store all the data of a
    //rider on the fair ride, this makes it easier so that I can make a queue of
    //type rider instead of multiple queues for each data type of data
    struct rider
    {
        //variable for last name of rider
        string lastName;
    
        //variable for number of tickets the rider has
        int tickets;
    
        //variable for the arrival time of the rider
        int time;
    };
    
    int main()
    {
        //variable used to count the ticket
        int tickets;
    
        //variable used to keep time
        int clock;
    
        //tmp variable used in loops as counter
        int i;
    
        //queue that the information from the infile gets stored into 
        queue<rider> arrivals;
    
        //queue that the riders with the correct clock time get put into
        queue<rider> line;
    
        //string that makes it easier to remember the name of the file to open
        //to read from
        string  inFileName = "riders.dat";
    
        //string that makes it easier to remember the name of the file to open
        //to write to
        string  outFileName = "riders.out";
       
        //file read from
        ifstream inFile;
    
        //file write to
        ofstream outFile;
        
        //opens the file to read from
        inFile.open(inFileName.c_str());
    
        //opens the file to write to
        outFile.open(outFileName.c_str());
    
        //sets the clock to 0
        clock = 0;
    
        //while the infile can be read from
        while(inFile)
        {
        
        //creates customer of the struct rider;
        rider customer;
    
        //it will loop and read from the inFile data while the customer data
        //is not equal to END 0 0 
        while(customer.lastName != 'END' && customer.tickets != 0 && customer.time != 0)
        {
            //here the file will place the correct data for each customer into 
            //the correct variables
            inFile >> customer.lastName >> customer.tickets >> customer.time;
    	
            //after the customer in that particular read is done putting it in the
            //correct variables the customer gets pushed ito arrivals queue
            arrivals.push(customer);
        }
    
        //once all the customers are read from the inFile and put into the arrivals
        //queue the program and clock will have to be run where this data will be 
        //processed. For the processing part of the program, it will run while
        //the queues arrivals and line are not empty, therefore they will stop
        //running when they become empty.
        while(arrivals.empty() != true && line.empty() != true)
        {
            //makes transfer a variable of type rider equal to the front of the
            //arrivals queue
            rider transfer = arrivals.front();
        
        //this will look to see if the transfer arrival time is equal to 0, if not
        //it will set clock equal to that number then copy all the transfers that
        //have that clock number.
        
            //checks to see if the transfer time is equal to the clock time
            if(transfer.time == clock)
            {
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(arrivals.front());
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
    
                //create a variable to store the rider that needs to get back
                //in line if they have more tickets
                rider backIn;
               
                //need to check to see if backIn is set to NULL or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(backIn != NULL)
                {
                
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn);
               
                }     
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //increments clock by 1 unit
                clock++;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                    //sets backIn equal to NULL so that later when the program
                    //loops through to see if it needs to add the customer back in
                    //to the line the program will see its set to NULL and not add
                    //blank space or previous data
                    backIn = NULL;
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //set the customers time equal to the clock time
                    onRide.time = clock;
    
                    //places the customer on the ride's data into the backIn 
                    //variable so they may get placed back in line 
                    backIn = onRide;
                }
            }
            //else if the first customers time is not equal to the clock it
            //sets clock equal to that customers time then continues on 
            else
            {
                //sets clock equal to the first customers time
                clock = transfer.time;            
    
                //will put all the customers with the same arrival 
                //time as the clock into the line queue
                while(transfer.time == clock)
                {
                //here the front of the arrivals queue is put into the line queue
                line.push(arrivals.front());
    
                //here the old front from the arrivals queue is popped off
                arrivals.pop();
                }
    
    
                //create a variable to store the rider that needs to get back
                //in line if they have more tickets
                rider backIn;
               
                //need to check to see if backIn is set to NULL or not, if it is
                //then it won't add anything, if not it will add the customers data 
                if(backIn != NULL)
                {            
               
                //if the rider from the previous time still has tickets left it
                //will be added after the next group of customers from that time
                line.push(backIn);
    
                }     
    
                //after the customers are added to the line queue the ride 
                //will begin to run, which entails taking away one ticket 
                //from the person on the ride then checking to see if any 
                //tickets are left and if so add to the end of the line queue
                //after the next group of customers enter, if no tickets are 
                //left then write out the name and the clock time to the out file.
            
                //creates a variable onRide to represent the front of the line
                //queue which represents that customer going on the ride
                rider onRide = line.front();
    
                //takes 1 ticket way from the customer that is going on the line
                onRide.tickets--;
    
                //increments clock by 1 unit
                clock++;
    
                //after the ride is completed it checks to see if the customer
                //that was just on the ride has more tickets to go back in line
                //or if it should be written to the outfile
    
                //if the customer on ride has 0 tickets the last name and the
                //clock time get printed out on the line to the outfile
                if(onRide.tickets == 0)
                {
                    //write the customers lastName and clock time to the outfile
                    outFile << onRide.lastName << clock << endl;
    
                    //sets backIn equal to NULL so that later when the program
                    //loops through to see if it needs to add the customer back in
                    //to the line the program will see its set to NULL and not add
                    //blank space or previous data
                    backIn = NULL;
                }
                //else if the cusomters ticket count is greater than 0 the customer
                //and his info will get stored into backIn to place the customer 
                //back in line
                else
                {
                    //set the customers time equal to the clock time
                    onRide.time = clock;
    
                    //places the customer on the ride's data into the backIn 
                    //variable so they may get placed back in line 
                    backIn = onRide;
                }
            }
        }
    }
    
        //closes the infile
        inFile.close();
    
        //closes the outfile          
        outFile.close();
    
        //signals ok to the os
        return 0;
    };
    the errors
    g++ main.cpp
    main.cpp:76:32: warning: multi-character character constant
    main.cpp: In function ‘int main()’:
    main.cpp:39: error: ‘queue’ was not declared in this scope
    main.cpp:39: error: expected primary-expression before ‘>’ token
    main.cpp:39: error: ‘arrivals’ was not declared in this scope
    main.cpp:42: error: expected primary-expression before ‘>’ token
    main.cpp:42: error: ‘line’ was not declared in this scope
    main.cpp:76: error: no match for ‘operator!=’ in ‘customer.rider::lastName != 4542020’
    main.cpp:122: error: no match for ‘operator!=’ in ‘backIn != 0’
    main.cpp:163: error: no match for ‘operator=’ in ‘backIn = 0’
    main.cpp:16: note: candidates are: rider& rider:perator=(const rider&)
    main.cpp:203: error: no match for ‘operator!=’ in ‘backIn != 0’
    main.cpp:244: error: no match for ‘operator=’ in ‘backIn = 0’
    main.cpp:16: note: candidates are: rider& rider:perator=(const rider&)
    make: *** [main] Error 1

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    First, #include <queue>?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    109
    wow yea i had it then must have deleted it for some reason thanks. Now my errors are as follows.
    main.cpp:77:32: warning: multi-character character constant
    main.cpp: In function ‘int main()’:
    main.cpp:77: error: no match for ‘operator!=’ in ‘customer.rider::lastName != 4542020’
    main.cpp:123: error: no match for ‘operator!=’ in ‘backIn != 0’
    main.cpp:164: error: no match for ‘operator=’ in ‘backIn = 0’
    main.cpp:17: note: candidates are: rider& rider:perator=(const rider&)
    main.cpp:204: error: no match for ‘operator!=’ in ‘backIn != 0’
    main.cpp:245: error: no match for ‘operator=’ in ‘backIn = 0’
    main.cpp:17: note: candidates are: rider& rider:perator=(const rider&)
    make: *** [main] Error 1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 05:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21