Jun 29, 2014 at 4:53pm UTC
I want to get help with this program, it gives an error - "Lvalue required".
What does it mean and how to remove it?
Thanks in advance:)
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
#include <include.h>
#include <conio.h>
class Tour
{
char Tcode[20];
int NoofAdults, NoofKids, Kilometers;
float TotalFare;
public :
Tour()
{
Tcode="NULL" ; //Here comes the Error
NoofAdults=0;
NoofKids=0;
Kilometers=0;
TotalFare=0;
}
void AssignFare(int NoofAdults, int NoofKids, int Kilometers)
{
if (Kilometers<500)
TotalFare=200*NoofAdults+100*NoofKids;
if (Kilometers<1000 && Kilometers>=500)
TotalFare=300*NoofAdults+150*NoofKids;
if (Kilometers>=1000)
TotalFare=500*NoofAdults+250*NoofKids;
}
void EnterTour()
{
cin>>Tcode>>NoofAdults>>NoofKids>>Kilometers;
AssignFare(NoofAdults, NoofKids, Kilometers);
}
void ShowTour();
{
cout<<"Tour Code : " <<Tcode<<"\n" ;
cout<<"No of Adults = " <<NoofAdults<<"\n" ;
cout<<"No of Kids = " <<NoofKids<<"\n" ;
cout<<"Kilometers = " <<Kilometers<<"\n" ;
cout<<"Total Fare = " <<TotalFare;
}
};
void main()
{
clrscr();
Tour T;
T.EnterTour();
T.ShowTour();
getch();
}
Last edited on Jun 29, 2014 at 5:16pm UTC
Jun 29, 2014 at 5:00pm UTC
What sort of creature is
'NULL"
?
It begins with a single quote and ends with a double quote.
Was it intended to be simply
NULL
or the character string
"NULL"
?
In either case, the assignment statement is attempting to modify the address of the character array Tcode, which is the main problem.
If you want to copy a C-string, use
strcpy()
:
http://www.cplusplus.com/reference/cstring/strcpy/
Last edited on Jun 29, 2014 at 5:06pm UTC
Jun 29, 2014 at 5:15pm UTC
there is no reason to assign Tcode to null
, why? char arrays are C concepts, there is really no reason to use them. use a std::string
in every case you think a char array would suffice.
Jun 29, 2014 at 5:20pm UTC
how to use std::string.
sorry but I am just a beginner
Jun 29, 2014 at 5:43pm UTC
std::string name = "Test Name" ;
then just use name variable anytime you want to use the string "Test Name".
Jun 29, 2014 at 5:55pm UTC
don't forget to include the library e.g. #include <string>
. Take a look at online string reference documentation to get an idea of what it is capable of
Jun 29, 2014 at 6:06pm UTC
i replaced Tcode="NULL"; with std::Tcode="NULL";
but now other errors come:-
1. ; statement missing.
2. Type qualifier 'std' must be a struct or class name
Jun 29, 2014 at 6:45pm UTC
I think this doesn't work in turbo C++, because it is giving me even more errors.