Help with simple problem !

hey guy I'm new and a noob in c++
need help with this simple program

Airline Booking System

write a code to solve these problems as following :

1- Define a variable represents the booking zone.
2- Display these sentences on the screen.

press 1 : to reserve in business man zone .
press 2 : to reserve in Normal people zone.

3- Define variables represents 5 seats for each zone (counter for each zone).
4- Reserve a ticket for one person (verify if there is empty seats than decrease the counter).

5- Repeat the above code to five seats.

this is my code and I know there is something wrong I don't know what !!

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{

int a,b;

cout<<"Press 1 : to reserve in business zone"<<endl;
cout<<"Press 2 : to reserve in economy zone"<<endl;

for (int i=0;i>=5;i=i+1)

{

cin>>a;
cout<<i;

while
(a=!5)
cout<<"you have reserved in business zone"<<endl;
}

for (int i=0;i>=5;i++)
{

cin>>b;
cout<<i;
}
while
(b=!5)
cout<<"You reserved in economy zone"<<endl;

cin>>a;
}
Last edited on
You and your class need to learn that school is for LEARNING if you don't want to learn c++ get a new career I've seen this same assignment several times this week.

Actually they are all from you.. Can you please TRY and not keep posting the same assignment saying "do my homework for me so I can pass my class without even trying." Please stop creating the same thread also http://www.cplusplus.com/forum/beginner/1/

When you have an actual question we can answer but you have yet to ask a question.
Last edited on
Well ask a question then don't tell us what to do.
it is a F****** question !
Are you asking why your code has an infinite loop? That would be because of your while loop inside of the first for loop
while( a != 5 ) std::cout << "blah blah" << std::endl;
You may want to reconsider that while statement. You also have this problem in the second loop. I would consider naming your variables with relevant names also not just a and b I have no clue what those are supposed to be. Also please use the code tags
[code][/code]
or the <> button when you edit/post a reply.

And saying you don't know what is wrong with your code is not a question. A question is like I think I have a problem at line ... because I wanted it to do this... but it is doing this.. what can I do to fix it?
The for loops shouldn't even execute. i is never greater than or equal to 5.
Yeah I didn't even notice that on his. Also you should consider using the standard way to write for loops for( int i = 0; i < MAX; ++i )
Also what is the purpose of outputting i? It will look like 012345.
ok
can you write a solution code?

so I can compare with my code?
How about you show us your "code." Then we can try to help you. You already posted 2 threads with write my code for me don't make this a third..or I'm going to blacklist you.
can you write a solution code?


I probably can if I wanted to invest my time into doing someone else's homework.
Here ya go. A very simple way to get you started. I provided a driver for you to experiment with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Zone 
{ 
public: 
    Zone(int availableSeats) 
    { 
        _availableSeats  = availableSeats;  
    }
    
    int Size() const { return _availableSeats; }
    bool ReserveSeat() { return _availableSeats-- > 0; }
    int AvailableSeats() const { return _availableSeats; }
    void PrintAvailableSeats(ostream& out) { out << "Available Seats: " << _availableSeats << endl; }
    
private:
    int _availableSeats;
};

class EconomyZone : public Zone 
{ 
public: 
    EconomyZone(int availableSeats) : Zone(availableSeats) { } 
};

class BusinessZone : public Zone 
{ 
public:
    BusinessZone(int availableSeats) : Zone(availableSeats) { } 
};


int main()
{
    EconomyZone ez(5);
   
    ez.ReserveSeat();
    ez.PrintAvailableSeats(cout);
    ez.ReserveSeat();
    ez.PrintAvailableSeats(cout);
    ez.ReserveSeat();
    ez.PrintAvailableSeats(cout);
    ez.ReserveSeat();
    ez.PrintAvailableSeats(cout);
    ez.ReserveSeat();
    ez.PrintAvailableSeats(cout);
     
    if (ez.ReserveSeat())
        cout << ez.AvailableSeats() << endl;
    else 
        cout << "No seats are available." << endl;
     

   return 0;
}
Last edited on
Why use a setter constructor in the zone class instead of a initialized list? Also your print function seems a bit weird Why not just make it void and just output the message on the function call or even overload operator <<. Also you know he is just going to copy/paste more than likely right? You should at least wait for him to "try" the assignment especially if they post the same topic 3 times within two days.
You're right about the initializer lists. As for my print method, I like it to be flexible so that I can print to the screen or pass in a filestream dynamically.

Topic archived. No new replies allowed.