Write two statements to read in values for my_city followed by my_state. Assign
ID: 3852324 • Letter: W
Question
Write two statements to read in values for my_city followed by my_state. Assign log_entry with current_time, my_city, and my_state. Values should be separated by a space. Sample output for given program if my_city is Houston and my_state is Texas: 2014-07-26 02:12:18: Houston Texas So far I have this code below, but I can't seem to overwrite the my_city and my_state to reflect Santa Barbara CA. current_time = '2014-07-26 02:12:18:' my_city = '' my_state = '' log_entry = '' my_city = ' Houston' my_state = ' Texas' log_entry = current_time + my_city + my_state print(log_entry) Please Help
Explanation / Answer
C++ Program:
#include <iostream>
#include <string>
#include <ctime>
#include<string>
using namespace std;
int main()
{
string my_city;
string my_state;
string log_Entry;
cout<<"Enter a city name ";
cin>>my_city;
cout<<"Enter a state name ";
cin>>my_state;
time_t now = time(0);
string dt = ctime(&now);
log_Entry=my_city+" "+my_state+" "+dt;
cout << "The log entry is: " << log_Entry << endl;
}
Output:
Enter a city name SantaBarbara
Enter a state name CA
The log entry is: SantaBarbara CA Tue Jun 27 05:06:17 2017
Note: You can execute the above C++program in C++ Shell online compiler
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.