Error - "Lvalue required"

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
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
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.
sorry it was "NULL"
how to use std::string.

sorry but I am just a beginner
std::string name = "Test Name";

then just use name variable anytime you want to use the string "Test Name".
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
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
i replaced Tcode="NULL"; with std::Tcode="NULL";

Tcode is not a member of the std namespace.
What you want at line 6 is:
1
2
 
  std::string Tcode;


Line 13 is fine as you have it.
1
2
 
  Tcode = "NULL";


And of course, as Need4Sleep mentioned, you'll need
 
#include <string>  





I think this doesn't work in turbo C++, because it is giving me even more errors.

It will be difficult to learn C++ using such an outdated compiler.

Some modern IDE/compilers are code::blocks, and the Orwell version of DevC++
http://www.codeblocks.org/
http://orwelldevcpp.blogspot.com/
Topic archived. No new replies allowed.