Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Paste BOTH your ideone.com link and code in the answer. Write a C++ program in i

ID: 3573264 • Letter: P

Question

Paste BOTH your ideone.com link and code in the answer. Write a C++ program in ideone.com that extracts and prints out the two character state when a city and state are input. The program assumes that the two character state is always entered last. YOU MUST WRITE THE PROGRAM SO THAT IT CAN ACCEPT ANY CITY, STATE For example, if "Los Angeles, CA" is input, then the output should be "CA", and if "Rochester, NY" is input, then the output should be "NY". The output should be: Enter a city and state Los Angeles, CA The state you entered was: CA

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;

int main (){
string mystr;
cout << "What's your name? ";
getline (cin, mystr);
cout << "Hello " << mystr << ". ";
string *token = strtok(mystr, ",");
token = strtok(NULL, ",");
cout << "The state you entered was: " << token << ' ';
return 0;
}