Thread: Can Anyone Can Help me??

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    22

    Can Anyone Can Help me??

    program is giving error .
    I am new to C++ .. I have implemented the code from what logic I made .. but code is giving error .. Help me
    Code:
    #include<conio.h>
    #include<iostream.h>
    class air_line
    {
    private:
    char name[5][100];
    int opt,opt1,cnic[5],ticket_number[5];
    public:
    void input()
    {
    for(int i=1;i=5;i++)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name[i];
    }
    for(int j=1;j<=5;j++)
    {
    cout<<"Please Enter Your CNIC Number : ";
    cin>>cnic[j];
    }
    for(int k=1;k<=5;k++)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number[k];
    }
    }
    void process()
    {
    cout<<"Enter your option  \n 1.Prices  \n 2.Ticket Confirmation \n  ";
    cin>>opt;
    if(opt==1)
    {
    cout<<"Select Journey \n 1.Abroad\n 2.Pakistan ";
    cin>>opt1;
    if(opt1==1)
    {
    cout<<" ";
    else if(opt1==2)
    {
    cout<<"*********************Prices for Pakistan*********************";
    cout<<"Islmabad To Karachi - 14000 PKR";
    cout<<"Islmabad To Lahore - 6000 PKR";
    cout<<"Islmabad To Peshawar - 8000 PKR";
    cout<<"Islmabad To Sialkot - 4000 PKR";
    cout<<"Islmabad To Quetta - 7000 PKR ";
    }
    else if(opt1==2)
    {
    cout<<"*********************Prices for Abroad*********************";
    cout<<"Islmabad To Dubai UAE - 24000 PKR";
    cout<<"Islmabad To Wishington - USA  - 60000 PKR";
    cout<<"Islmabad To California - USA - 120000 PKR";
    cout<<"Islmabad To China - 20000 PKR";
    cout<<"Islmabad To Iran - 17000 PKR ";
    }
    else
    {
    cout<<"Wrong Statement Entered";
    }
    }
    if(opt==2)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name;
    cout<<"Please Enter Your CNIC Number :";
    cin>>cnic;
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number;
    for(int y=1;y<=5;y++)
    {
    cout<<"\n Eearch about these ticket no is:";
    cin>>ticket_number[i];
    }
    
    
    cout<<"\nenter search ticket no is:";
    cin>>ticket_no;
    for (i=0;i<=5;i++)
    if(ticket_number[1]==ticket_no)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[1];
    cout<<"\n Ticket Number : is that "<<ticket_no[1];
    cout<<"\n CNIC No. :"<<cinic[1];
    }
    else if(ticket_number[2]==ticket_no)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[2];
    cout<<"\n Ticket Number is "<<ticket_no[4];
    cout<<"\n CNIC No. :"<<cinic[2];
    }
    else if(ticket_number[3]==ticket_no)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[2];
    cout<<"\n Ticket Number is "<<ticket_no[2];
    cout<<"\n CNIC No. :"<<cinic[2];
    }
    else if(ticket_number[4]==ticket_no)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[4];
    cout<<"\n Ticket Number is "<<ticket_no[4];
    cout<<"\n CNIC No. :"<<cinic[4];
    }
    else if(ticket_number[5]==ticket_no)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[5];
    
    
    cout<<"\n Ticket Number is "<<ticket_no[5];
    cout<<"\n CNIC No. :"<<cnic[5];
    }
    };
    air_line tahir;
    tahir.input();
    tahir.process();
    getch();
    }
    }
    Last edited by rajatahirqaiser; 06-01-2013 at 01:27 PM.

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    I'll give you a few pointers, but sorting through this sort of stuff is part of learned.

    First, INDENT YOUR CODE!! Please! It is very difficult to know what's going on when there's no indentation.

    Secondly, try taking it in smaller chunks. Get one bit working, then move on to the next bit. Try to get in the habit of building and testing as you go, rather than waiting til you're 'done'. I'd suggest making a copy of your work and then ripping bits out of it until it works.

    I've pulled out the first function in your class and indented it:

    Code:
    #include <conio.h>
    #include <iostream.h>
    
    class air_line
    {
    private:
        char name[5][100];
        int opt,opt1,cnic[5],ticket_number[5];
    public:
        void input()
        {
            for(int i=1;i=5;i++)
            {
                cout<<"Please Enter Your Name : ";
                cin>>name[i];
            }
            for(int j=1;j<=5;j++)
            {
                cout<<"Please Enter Your CNIC Number : ";
                cin>>cnic[j];
            }
            for(int k=1;k<=5;k++)
            {
            cout<<"Please Enter Your Ticket Number : ";
            cin>>ticket_number[k];
            }
        }
    };
    Next, I'd test this function on its own and see if it works.

    You have some code at the end of the file that looks like test code. but it's not in any function. That'll upset the compiler a lot!! Put it in main: Structure of a program - C++ Documentation

    Then, see if builds. If you get errors, try to figure out what's wrong, and post the errors and explain what you've tried if you can't figure it out. It's a lot easier to reply to specific questions!

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    22
    Man,
    I have coded the program so that when it run, first it will ask the user to enter name , cnic number and ticket number for 5 times... than it asks for "Enter your option \n 1.Prices \n 2.Ticket Confirmation "

    if user goes 1
    than program will ask for abroad or for pakistan show prices ( simply cout the code )

    if user goes for ticket confirmation that is 2 than program will ask to enter name cnic and ticket number and than search from what it has already got from user in start of program ( 5 5 5 name cnic ticket number )

    P.S my english is not good

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    char name[5][100];
    int opt,opt1,cnic[5],ticket_number[5];
    public:
    void input()
    {
    for(int i=1;i=5;i++)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name[i];
    }
    1. You have =, where you should have some kind of comparison.

    2. All your loops start at 1, not 0
    Meaning all your arrays are being overrun.

    Use
    for ( int i = 0 ; i < 5 ; i++ )
    to loop through those arrays.
    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.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    22
    Some how corrected But still some errors
    Code:
    #include<conio.h>#include<iostream.h>
    class air_line
    {
    private:
    char name[5][100],name;
    int opt,opt1,cnic[5],ticket_number[5],ticket_number1,cnic1;
    public:
    void input()
    {
    for(int i=1;i=5;i++)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name[i];
    }
    for(int j=1;j<=5;j++)
    {
    cout<<"Please Enter Your CNIC Number : ";
    cin>>cnic[j];
    }
    for(int k=1;k<=5;k++)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number[k];
    }
    }
    void process()
    {
    cout<<"Enter your option  \n 1.Prices  \n 2.Ticket Confirmation \n  ";
    cin>>opt;
    if(opt==1)
    {
    cout<<"Select Journey \n 1.Abroad\n 2.Pakistan ";
    cin>>opt1;
    if(opt1==1)
    {
    cout<<" ";
    else if(opt1==2)
    {
    cout<<"*********************Prices for Pakistan*********************";
    cout<<"Islmabad To Karachi - 14000 PKR";
    cout<<"Islmabad To Lahore - 6000 PKR";
    cout<<"Islmabad To Peshawar - 8000 PKR";
    cout<<"Islmabad To Sialkot - 4000 PKR";
    cout<<"Islmabad To Quetta - 7000 PKR ";
    }
    else if(opt1==2)
    {
    cout<<"*********************Prices for Abroad*********************";
    cout<<"Islmabad To Dubai UAE - 24000 PKR";
    cout<<"Islmabad To Wishington - USA  - 60000 PKR";
    cout<<"Islmabad To California - USA - 120000 PKR";
    cout<<"Islmabad To China - 20000 PKR";
    cout<<"Islmabad To Iran - 17000 PKR ";
    }
    else
    {
    cout<<"Wrong Statement Entered";
    }
    }
    if(opt==2)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number1;
    }
    
    
    for (int m=1;m<=5;m++)
    {
    if(ticket_number[k]==ticket_number1)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[i];
    cout<<"\n Ticket Number : is that "<<ticket_number[k];
    cout<<"\n CNIC No. :"<<cinic[j];
    }
    }
    };
    air_line tahir;
    tahir.input();
    tahir.process();
    getch();
    }
    Last edited by rajatahirqaiser; 06-01-2013 at 02:29 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Somehow, it's still got all your buffer overrun issues.
    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.

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    22
    updated code .. more errors debugged ... help me to fix them .. little bit confused how to add search in last ... help me
    Code:
    #include<conio.h>#include<iostream.h>
    class air_line
    {
    private:
    char name[5][100],name1;
    long double opt,opt1,opt2,cnic[5],ticket_number[5],ticket_number1,cnic1;
    public:
    void input()
    {
    for(int i=1;i=5;i++)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name[i];
    }
    for(int j=1;j<=5;j++)
    {
    cout<<"Please Enter Your CNIC Number : ";
    cin>>cnic[j];
    }
    for(int k=1;k<=5;k++)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number[k];
    }
    }
    void process()
    {
    cout<<"Enter your option  \n 1.Prices  \n 2.Ticket Confirmation \n  ";
    cin>>opt;
    if(opt==1)
    {
    cout<<"Select Journey \n 1.Abroad\n 2.Pakistan ";
    cin>>opt1;
    }
    if(opt1==1)
    {
    cout<<"Where You want to go \n 0.Pakistan \n 1.Abroad";
    cin>>opt2;
    }
    	if(opt2==0)
    {
    cout<<"*********************Prices for Pakistan*********************";
    cout<<"Islambad To Karachi - 14000 PKR";
    cout<<"Islambad To Lahore - 6000 PKR";
    cout<<"Islambad To Peshawar - 8000 PKR";
    cout<<"Islambad To Sialkot - 4000 PKR";
    cout<<"Islambad To Quetta - 7000 PKR ";
    }
    	if(opt2==1)
    {
    cout<<"*********************Prices for Abroad*********************";
    cout<<"Islmabad To Dubai UAE - 24000 PKR";
    cout<<"Islmabad To Wishington - USA  - 60000 PKR";
    cout<<"Islmabad To California - USA - 120000 PKR";
    cout<<"Islmabad To China - 20000 PKR";
    cout<<"Islmabad To Iran - 17000 PKR ";
    }
    else
    {
    cout<<"Wrong Statement Entered";
    }
    
    
    if(opt==2)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number1;
    }
    
    
    for (int k=1;k<=5;k++)
    {
    if(ticket_number[k]==ticket_number1)
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[i];
    cout<<"\n Ticket Number : is that "<<ticket_number[k];
    cout<<"\n CNIC No. :"<<cnic[j];
    }
    }
    };
    main();
    {
    
    
    
    
    
    
    
    
    clrscr()
    air_line tahir;
    tahir.input();
    tahir.process();
    getch();
    }

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Still no indentation and you still have array overruns. Re-read post number 4.

    Jim

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You have a very short running program. This assumes it compiles.

    Tim S.

    Code:
    main();
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Stop using char arrays. Start using std::string.
    Study on how to use arrays in a safe way in C++ and how to more easily catch errors when using them incorrectly: SourceForge.net: Safer arrays in Cpp - cpwiki
    main should also return int; omitting return types for functions is illegal. There should be no semicolon after function definitions. You only apply them for function prototypes.
    Last edited by Elysia; 06-01-2013 at 11:14 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Nov 2012
    Posts
    22
    Help me to correct the [search ] at the end of the program
    Code:
    #include<conio.h>#include<iostream.h>
    class air_line
    {
    private:
    char name[5][100],name1;
    long double opt,opt1,opt2,cnic[5],ticket_number[5],ticket_number1,cnic1;
    public:
    void input()
    {
    for(int i=1;i<=5;i++)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name[i];
    }
    for(int j=1;j<=5;j++)
    {
    cout<<"Please Enter Your CNIC Number : ";
    cin>>cnic[j];
    }
    for(int k=1;k<=5;k++)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number[k];
    }
    }
    void process()
    {
    cout<<"Enter your option  \n 1.Prices  \n 2.Ticket Confirmation \n  ";
    cin>>opt;
    if(opt==1)
    {
    cout<<"Select Journey \n 1.Abroad\n 2.Pakistan ";
    cin>>opt1;
    }
    if(opt1==1)
    {
    cout<<"Where You want to go \n 0.Pakistan \n 1.Abroad";
    cin>>opt2;
    }
    	if(opt2==0)
    {
    cout<<"*********************Prices for Pakistan*********************";
    cout<<"Islambad To Karachi - 14000 PKR";
    cout<<"Islambad To Lahore - 6000 PKR";
    cout<<"Islambad To Peshawar - 8000 PKR";
    cout<<"Islambad To Sialkot - 4000 PKR";
    cout<<"Islambad To Quetta - 7000 PKR ";
    }
    	if(opt2==1)
    {
    cout<<"*********************Prices for Abroad*********************";
    cout<<"Islmabad To Dubai UAE - 24000 PKR";
    cout<<"Islmabad To Wishington - USA  - 60000 PKR";
    cout<<"Islmabad To California - USA - 120000 PKR";
    cout<<"Islmabad To China - 20000 PKR";
    cout<<"Islmabad To Iran - 17000 PKR ";
    }
    else
    {
    cout<<"Wrong Statement Entered";
    }
    
    
    if(opt==2)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number1;
    }
    
    
    for (int k=1;k<=5;k++)
    {
    if(ticket_number1==ticket_number[k])
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[i];
    cout<<"\n Ticket Number : is that "<<ticket_number[k];
    cout<<"\n CNIC No. :"<<cnic[j];
    }
    }
    };
    main();
    {
    clrscr();
    air_line tahir;
    tahir.input();
    tahir.process();
    getch();
    }

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Do you know what "indent your code" means?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The OP has failed to fix anything mentioned so far.
    If you do not understand what we are telling you, then say so.
    Otherwise you are just wasting our time.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Nov 2012
    Posts
    22
    1 error remainig .. decleration terminated in correctly ... but i am unable to findout ... :/
    Code:
    #include<conio.h>#include<iostream.h>
    class air_line
    {
    private:
    char name[5][100],name1;
    long double opt,opt1,opt2,cnic[5],ticket_number[5],ticket_number1,cnic1;
    public:
    void input()
    {
    for(int i=1;i<=5;i++)
    {
    cout<<"Please Enter Your Name : ";
    cin>>name[i];
    cout<<"Please Enter Your CNIC Number : ";
    cin>>cnic[i];
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number[i];
    }
    }
    void process()
    {
    cout<<"Enter your option  \n 1.Prices  \n 2.Ticket Confirmation \n  ";
    cin>>opt;
    if(opt==1)
    {
    	cout<<"Select Journey \n 1.Abroad\n 2.Pakistan ";
    	cin>>opt1;
    }
    if(opt1==1)
    {
    	cout<<"Where You want to go \n 0.Pakistan \n 1.Abroad";
    	cin>>opt2;
    }
    	if(opt2==0)
    {
    cout<<"*********************Prices for Pakistan*********************";
    cout<<"Islambad To Karachi - 14000 PKR";
    cout<<"Islambad To Lahore - 6000 PKR";
    cout<<"Islambad To Peshawar - 8000 PKR";
    cout<<"Islambad To Sialkot - 4000 PKR";
    cout<<"Islambad To Quetta - 7000 PKR ";
    }
    	if(opt2==1)
    {
    cout<<"*********************Prices for Abroad*********************";
    cout<<"Islmabad To Dubai UAE - 24000 PKR";
    cout<<"Islmabad To Wishington - USA  - 60000 PKR";
    cout<<"Islmabad To California - USA - 120000 PKR";
    cout<<"Islmabad To China - 20000 PKR";
    cout<<"Islmabad To Iran - 17000 PKR ";
    }
    else
    {
    cout<<"Wrong Statement Entered";
    }
    
    
    if(opt==2)
    {
    cout<<"Please Enter Your Ticket Number : ";
    cin>>ticket_number1;
    }
    
    
    for (int i=1;i<=5;i++)
    {
    if(ticket_number1==ticket_number[i])
    {
    cout<<"\n Your Info is Following : ";
    cout<<"\n Name of Passenger is: "<<name[i];
    cout<<"\n Ticket Number : is that "<<ticket_number[i];
    cout<<"\n CNIC No. :"<<cnic[i];
    }
    }
    };
    main()
    {
    clrscr();
    air_line tahir;
    tahir.input();
    tahir.process();
    getch();
    }

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This one is going to the ignore list.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed