I am coding this simple program which is supposed to create a user profile with given attributes. I am testing the method view_profile()
which is supposed to just return a string with the values given from the constructor. When I run the program I get no errors, but the output is not expected. I am wondering why in the output the Name: Sam Drakillanouns is appearing, instead of Name: Sam Drakilla, also, age variable is not showing.
#include <iostream>
#include <vector>
using namespace std;
class Profile {
private:
string name;
int age;
string city;
string country;
string pronouns;
vector<string> hobbies;
public:
//Constructor
Profile(string name1, int age1, string city1, string country1, string pronouns1 = "they/them") {
name = name1;
age = age1;
city = city1;
country = country1;
pronouns = pronouns1;
}
//View Profile method
string view_profile() {
string bio = "Name: " + name;
bio += "\nAge: " + age;
bio += "\nCity: " + city;
bio += "\nCountry: " + country;
bio += "\nPronouns: " + pronouns;
bio += "\n";
return bio;
}
};
int main() {
Profile sam("Sam Drakkila", 30 , "New York", "USA", "he/him");
cout << sam.view_profile();
}
My output is:
Name: Sam Drakillanouns:
City: New York
Country: USA
Pronouns: he/him
when is should be:
Name: Sam Drakilla
Age: 30
City: New York
Country: USA
Pronouns: he/him
I tried to check the constructor and method view_profile()
but everything seems to be correct. I may be overlooking something since I am new to the C++ language.