#include <iostream>
#include <string>
usingnamespace std;
int longi();
int main()
{
string name;
cout<<"Hello sir, what is your name?\n";
cin>>name;
cout<<"Your name is '"<< name << "'\n";
longi()=name; // I get the error here
return 0;
}
int longi(){
string name;
cout<<"your name is "<<name.size()<<" letters long";
}
It sounds like you'd want to make longi() take a string parameter so you can send the name entered in main to the function. If you're doing the output in the function, it doesn't need to return anything, so you can make the return type void.
1 2 3 4
void longi(string name)
{
cout << "your name is " << name.size() << " letters long";
}
#include <iostream>
#include <string>
usingnamespace std;
int longi(name);
int main()
{
string name;
cout<<"Hello sir, what is your name?\n";
cin>>name;
cout<<"Your name is '"<< name << "'\n";
longi(name)=name;
return 0;
}
void longi(string name){
string name;
cout<<"your name is "<<name.size()<<" letters long";
}
You don't need the variable name in the prototype, but you do need the data types to match. (edit - in both the return type and the types of the parameters)
int longi(name);
void longi(string name)
Just call the function. Don't try to make it equal to anything. It's not returning a valid lvalue. longi(name)=name;
line 20 - you don't need to declare a new name variable in the function.
#include <iostream>
#include <string>
usingnamespace std;
void longi(string name);
int main()
{
string name;
cout<<"Hello sir, what is your name?\n";
cin>>name;
cout<<"Your name is '"<< name << "'\n";
longi(name);
return 0;
}
void longi(string name)
{
cout<<"your name is "<<name.size()<<" letters long";
}
Hello sir, what is your name?
Mary
Your name is 'Mary'
your name is 4 letters long