I have the following C++ code and when I compile it I get the “Lvalue required” error. Please point out where I’m going wrong. Thanks.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
char r[5];
int mark;
cout<<"Please enter your goddamn marks";
cin>>mark;
r=mark>=35?"pass":"fail";
cout<<"\n"<<r;
}
The problem is here:
You cannot assign a string literal to a
chararray. You have several options:strcpy()instead of assignment;rto be of typeconst char*;rto be of typestd::string.The last option is by far the best.