-
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();
}
}
-
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!
-
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
-
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.
-
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();
}
-
Somehow, it's still got all your buffer overrun issues.
-
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();
}
-
Still no indentation and you still have array overruns. Re-read post number 4.
Jim
-
You have a very short running program. This assumes it compiles.
Tim S.
-
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.
-
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();
}
-
Do you know what "indent your code" means?
-
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.
-
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();
}
-
This one is going to the ignore list.