So I have this
int main(){
string input;
string lastName;
string firstName;
int age;
int streetNum;
string streetName;
string town;
string zipCode;
float balance;
Update(lastName, firstName, age, streetNum, streetName, town, zipCode, balance);
}
and here is the function Update
void Update(string &lastname, string &firstname, int &age, int &streetnum, string &streetname, string &town, string &zipcode, float &balance){
cout << "Update the following, enter nothing to leave the same: " << endl;
string input;
cout << "Last name: ";
getline(cin, input);
if (input != "\n") { lastname = input; }
cout << "First name: ";
getline(cin, input);
if (input != "\n") { firstname = input; }
cout << "Age: ";
getline(cin, input);
if (input != "\n") { age = atoi(input.c_str()); }
cout << "Street number: ";
getline(cin, input);
if (input != "\n") { streetnum = atoi(input.c_str()); }
cout << "Street name: ";
getline(cin, input);
if (input != "\n") { streetname = input; }
cout << "Town name:";
getline(cin, input);
if (input != "\n") { town = input; }
cout << "ZipCode: ";
getline(cin, input);
if (input != "\n") { zipcode = input; }
cout << "Balance: ";
getline(cin, input);
if (input != "\n") { balance = atof(input.c_str()); }
}
My goal is to update the value or skip to the next value if the input is '\n'.
Once running and the program calls Update, it prints out "Last Name: First Name: " on the same line without letting the user input anything into lastname. I have no idea why it does this. Any tips or clues to directions to go in would be helpful.