Please enter the name of your favorite city in lower case: (user for example enters) chicago
chicago is supposed to be data entered by the user.
my question is what code should i enter to enable the user to enter such data and how can i use that data (chicago) with the rest of my code.
I hope I made myself clear. I am still a beginner.
What are you really intending to do? Why in lower case, should user response be sent back to stdout with the first letter in upper case? Does this need to repeat a certain number of times etc?
//chicago.cpp
//Assignment
#include <iostream> //allows program to input and output data.
using std::cout; //standard output stream object
using std::cin; //standard input stream object
using std::endl;
#include <string> //allows program use string objects
using std::string; //standard string object
using std::getline; //allows program input a string
int main(){ //begins program execution
string city; //declare a string variable
//prompt user to input a city name
cout<<"Please enter the name of your favorite city in lower case: ";
getline(cin,city); //read string from user into city string variable
cout<<"\nYour favorite city is: "<<city<<endl; //display message + city variable + new line
return 0; //indicates success
}//end function main
Eyenrique-MacBook-Pro:Help Eyenrique$ ./chicago
Please enter the name of your favorite city in lower case: chicago
Your favorite city is: chicago
after the user enters his favorite city, the app must look like this
Tom’s City Name Manipulator
-----------------------------
Please enter the name of your favorite city in lower case: chicago
You entered chicago which has 7 characters.
Here is the city name:
With the second letter in upper case: cHicago
With the second to last letter in upper case: chicaGo
With the middle letter in uppercase: chicAgo
We're not going to write your entire code for you. eyenrique has already gone further than most people here have, by writing a working program for you, showing you how you read the user input, and the starting point for how to output it. Now you try completing it from here. We'll help you with problems you encounter, but we're not a free homework service.
//chicago.cpp
//Assignment
#include <iostream> //allows user to input and output data.
using std::cout; //standard output stream object
using std::cin; //standard input stream object
using std::endl;
#include <string> //allows program use string objects
using std::string; //standard string object
using std::getline; //allows program input a string
int main(){ //begins program execution
string city; //declare a string variable
//prompt user to input a city name
cout<<"Please enter the name of your favorite city in lower case: ";
getline(cin,city); //read string from user into city string variable
cout<<"\nYou entered: "<<city<<" which has "<<city.size()<<" characters."<<endl;
return 0; //indicates success
}//end function main
Please enter the name of your favorite city in lower case: chicago
You entered: chicago which has 7 characters.