Need Some Help

Need some help with some coding.

This is what I would like to do.


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.

Thank you.
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?
Yes.
Following what the user enters (in this case chicago)
i must use the city and display it in several ways.

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
I don't know what are you trying to do,
but this may help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//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
Last edited on
This definetly helps.
however,

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

the bold is data entered by the user

that is it
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.
Try to do the rest!
string objects have special functions,
read about strings in the reference section.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//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.
Topic archived. No new replies allowed.