char gender;
string name;
cout<<"Please enter gender (m/f): "; //gender selection done as a simple if else statement.
cin>> gender;
cout<<endl;
if (gender == 'm') // m = male
cout<< "Sir, what is you name? " <<flush;
else //f = female output
cout<< "Madam, what is you name? " <<flush;
getline(cin, name);
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout<<endl;
cout<< "Your name adds up to " ;
int sum = 0;
for(a = 0; a!= name.length( ); ++a)
{
sum += int(name[a]);
}
cout<<sum;
this is the program Ive written. If I input just 'm' for the gender and then input a name the sum outputs 0
if I input 'male' then it outputs and then I input a name it outputs a value but its not the correct ascii value.