Hello everyone! I'm new here as I'm new to programming, right now I'm studying how to write my own functions. After a couple of exercise i tried writing a void function but i get the error " expected primary expression before 'a' "
#include <iostream>
#include <string>
usingnamespace std;
void box_string(string x)
{
int n = x.length();
for(int i = 0; i < n + 2; i++){cout<<"-";}
cout<<endl;
cout<< "!" << x << "!" << endl;
for(int i = 0; i < n + 2; i++){cout<<"-";}
cout<<endl;
}
int main()
{
string a = "Hello";
a = box_string(string a);
return 0;
}
#include <iostream>
#include <string>
usingnamespace std;
void box_string(string x)
{
int n = x.length();
for (int i = 0; i < n + 2; i++){ cout << "-"; }
cout << endl;
cout << "!" << x << "!" << endl;
for (int i = 0; i < n + 2; i++){ cout << "-"; }
cout << endl;
}
int main()
{
string a = "Hello";
//a = box_string(string a); // It doesn't return any value.
// The variable type "string" cannot
// accompany with the variable when
// you are calling the function.
box_string(a); // Since it doesn't return a value.
// You are calling the function to execute.
return 0;
}
Oh dear! Of course! It doesn't return a value! I just need to create a string and then call the function with the string_name inside the parentheses! Thanks a lot both of you!