Like Tree1Likes
  • 1 Post By Salem

Very entry level errors...

This is a discussion on Very entry level errors... within the C++ Programming forums, part of the General Programming Boards category; This is slightly embarrassing but I have reread my syntax and it is spot on. Although my code is not ...

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    6

    Angry Very entry level errors...

    This is slightly embarrassing but I have reread my syntax and it is spot on. Although my code is not complete, it should function as is until I add the oter functions later. If anyone can help me, please do not give me the fix for the code but maybe point out my mistake? thank you!

    Code:
    #include <iostream>
    #include<string>
    #include<fstream>
    using namespace std;
    
    
    
    
    void menu();
    void seatReserve();
    void emptyRow();
    void emptyPlane();
    
    
    const int NUM_ROWS = 15;
    const int NUM_SEATS = 6;
    int seats[NUM_ROWS][NUM_SEATS] = { 0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0, 
                                       0, 0, 0, 0, 0, 0, 
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0, 
                                       0, 0, 0, 0, 0, 0, 
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0,
                                       0, 0, 0, 0, 0, 0, 
                                       0, 0, 0, 0, 0, 0};
    double prices[NUM_ROWS][NUM_SEATS]; 
    
    
    
    
    
    
    
    
    
    
    int main
    {
    
    
    
    
        cout << "Welcome to the aircraft inventory tool\n";
        menu();
    
    
    return 0;
    
    
    }
    
    
    void menu()
    {
        cout << "Please select an option from the following menu:\n"
             << "1 - Reserve a seat\n"
             << "2 - Display total seats sold\n"
             << "3 - Display total seats empty in a row\n"
             << "4 - Display total seats empty on the plane\n"
             << "5 - Display total amount in sales\n";
        cin >> choice;
        if (choice == 1)
            seatReserve();
        
        //else if (choice == 2)
            //seatsSold();
            
        else if (choice == 3)    
            emptyRow();
            
        else if (choice == 4)
            emptyPlane();
        
        //else if (choice == 5)
            //amountSales();
    }    
    
    
    void seatReserve()
    {
        int row,col, seat;
        cout << "Please enter the seat row and number you would like to reserve in this format\n"
             << "1 5\n"
             << "Please keep in mind that that the first 5 rows are first class and are the most expensive and olny have 4 seats and the second 5 rows are more expensive than the last 5\n";
             
        cin >> row,col;
        
        while (row <= 5 && col > 4)
        {    
            cout << "That is not a valid seat number\n";
            cin >> row, col;
        }    
        seat = seats[row][col]
        
        while (seat == 1)
        {    
            cout << "We are sorry, that seat is already taken, please selct another\n";
            cin >> row, col;
            seat = seats[row][col];
        }    
        
        cout << "Your seat has been reserved\n";
        seat = 1;
        menu();
    }        
            
        
    
    
        
        
    void emptyRow()
    {
        int row, rowEmpty;
        cout << "Please enter the row that you need the empty seat count for:\n";
        cin >> row;
        
        if (row <= 5)
        {
            for ( int rowPlus = 0; rowPlus < NUM_SEATS; rowPlus++)
                rowEmpty += seats[row][rowPlus]
                
            rowEmpty = 4 - rowEmpty
        }        
                
        if (row <= 15 && row > 5)
        {
            for ( int rowPlus = 0; rowPlus < NUM_SEATS; rowPlus++)
                rowEmpty += seats[row][rowPlus]
                
            rowEmpty = 6 - rowEmpty
        }        
        
        cout << "That row has " << rowEmpty << " empty seats\n";
    }    
    
    
    void emptyPlane()
    {
        int planeEmpty;
        for ( int row = 0; row < NUM_ROWS; row++)
        {
            for (int col =0; col < NUM_SEATS; col++)
                planeEmpty += seats[row][col]
        }        
        
        planeEmpty = 80 - planeEmpty
        
        cout << "The plane has " << planeEmpty << " empty seats\n";
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    How does it not work?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    6
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:41:52: error: expected '}' before ';' token
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:41:52: error: invalid conversion from 'void*' to 'int' [-fpermissive]
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:42:11: error: expected constructor, destructor, or type conversion before ';' token
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:44:1: error: expected unqualified-id before 'return'
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:46:1: error: expected declaration before '}' token

    Is what I'm getting

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > please do not give me the fix for the code but maybe point out my mistake?
    Your first mistake was writing emptyRow() and emptyPlane before making sure that seatReserve() compiled and executed properly.

    You don't write a large program by bashing the keyboard for hours, then wondering why there are 100's of errors.

    Write code in small steps, compile often (every few lines), test whenever you have a complete function.
    I'll leave it to you to figure out your comfort zone for how much you can write before pressing compile, and still feel comfortable dealing with the errors.

    Writing 100's of lines and then dumping it all on a forum for someone else to fix isn't going to work.

    > cin >> row,col;
    Compare the syntax you use to output multiple values using cout? Does that use commas?

    > if (row <= 15 && row > 5)
    So if I buy a new plane, and change
    const int NUM_ROWS = 25;
    does your code carry on working?

    Finally, you're missing a whole bunch of ; at the ends of many lines.

    TBH, this looks more like a "fix the errors" assignment, where a tutor hands out deliberately broken code just to see if students can fix the problems.
    rags_to_riches likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,761
    I think most of the errors are occuring because the main function is missing an argument list. That doesn't have anything to do with what the errors say, exactly, but that is obviously wrong. Try fixing that first.

    Also, I want to point out that seatReserve() calls menu(), perhaps unnecessarily. There are not enough seats on the plane to potentially cause a problem, but mind the call stack. Could the program be designed so that seatReserve() finishes executing before menu() is called again?

  6. #6
    Registered User
    Join Date
    May 2013
    Posts
    6
    Thank you for the tips, I will definitely start using them. But I dont understand some of the syntax errors. illegal conversion of void to int>? where m I doing that>? expecting another } before ;? I counted them, and they are all there.
    I dont get these:
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:41:52: error: expected '}' before ';' token
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:41:52: error: invalid conversion from 'void*' to 'int' [-fpermissive]
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:42:11: error: expected constructor, destructor, or type conversion before ';' token
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:44:1: error: expected unqualified-id before 'return'
    C:\Users\river_000\Desktop\pocketcpp\pocketcpp\pro ject.cpp:46:1: error: expected declaration before '}' token

    I did fix the things you guys suggested but the errors are exactly the same

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    What is your current code?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    At the very least, you need to follow this advice, then re-post your code and compile errors. It is a mistake you have made at least 7 times, which will cause numerous unexpected compile errors:
    Quote Originally Posted by Salem View Post
    >Finally, you're missing a whole bunch of ; at the ends of many lines.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Registered User
    Join Date
    May 2013
    Posts
    6
    I can't seem to post the code, it is telling me to add code tags which I added but it is till not letting me post. I even deleted everything before and after code tags. right?
    I basically took the code from above and found alot missing semi colons and removed the call to the function menu like suggested but compile errors are exactly the same

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    Well you managed to post code just fine in your first post.

    Anything which contains curly braces should be between [code][/code] tags.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    The code and errors you posted originally did not line up. There is no code on line 41 where it states there are errors.
    Try fixing your "int main" which should be "int main()" which is on a close line number.

    Don't be fooled into thinking that fixing the missing semicolons did nothing. Those were still errors which if it wasn't showing you already, was likely just to not bamboozle you with too many errors at once.

    If you give up trying to post the code then I'm afraid we may have to give up helping you. If you did it once, you can do it again.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. entry level homework help: Passing Arrays into functions.
    By DHart07 in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2010, 10:11 AM
  2. Entry Level Programming Jobs
    By bengreenwood in forum General Discussions
    Replies: 5
    Last Post: 09-21-2009, 01:14 PM
  3. Entry Level Help.
    By alex1067 in forum C Programming
    Replies: 21
    Last Post: 03-11-2008, 06:13 PM
  4. Entry Level help.
    By alex1067 in forum C++ Programming
    Replies: 8
    Last Post: 03-10-2008, 10:26 PM
  5. Salary for entry level C position- How much can you make?
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-11-2002, 12:54 AM

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