954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ Strings PLEASE HELP

I AM HAVING A HARD TIME WITH STRINGS. I DO NOT FULLY UNDERSTAND IT. THIS IS FROM A BASIC INTRO C++ CLASS HW PLEASE HELP THIS IS THE QUESTION

Write a program that uses cin to read a given name (like Louis) and a family name (like Armstrong) into two string variables, given and family. The program then makes assignments to two other string variables: givenFirst and givenLast. To givenFirst it assigns the concatenation of given, a space, and family. To givenLast, it assigns the concatenation of family, a comma followed by a space, and given.

The program then prints on two separate lines the values of givenFirst and givenLast.

So if the user typed in "

HERE'S WHAT I DID.............
int main () {
string given, family;
String givenFirst, givenLast;


cout << “Louis:”;
cin >> given;
cout << “Armistrong:”
cin >> family;

name1=given + “ “ + family;
name2 = givenLast + “,” + givenFirst;

cout << name1 << end1;
cout << name2 << end1;

return 0;
}

aznswti85
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 
name2 = givenLast + “,” + givenFirst;

givenLast and givenFirst are not initialized.

dkalita
Posting Pro in Training
402 posts since Sep 2009
Reputation Points: 121
Solved Threads: 61
 

First of all, please type in all the code between the CODE tags.

Secondly, you used "String" instead of "string" to initialize givenFirst and givenLast. C++ is case-sensitive, which means that there is a difference between upper-case and lower-case letters.

pspwxp fan
Junior Poster
100 posts since Feb 2009
Reputation Points: 43
Solved Threads: 7
 

how do i initialize givenFirst and givenLast?

aznswti85
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

Well, what dkalita means is that.... no value is assigned to the variables. givenFirst and givenLast.

Apart from that there are many other mistakes in your program.

Firstly, the declaration of the variables givenFirst is wrong because string should be in the place of String notice the capital 'S'

Apart from that. the variables. name1 and name2 are not declared anywhere.

Sky Diploma
Practically a Posting Shark
865 posts since Mar 2008
Reputation Points: 673
Solved Threads: 131
 

Yes i already know about the case sensitive C++ and have fixed that error already but nobody is answering my question. HOW DO I DECLARE A STRING?? HOW DO I FIX WHAT IS WRONG WITH THIS CODE????????????????

aznswti85
Newbie Poster
3 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

>>WHAT IS WRONG WITH THIS CODE?
1) You do not use code tags
2) You haven't included the necessary library
3) I don't think you understand what the question is asking, so
understand it before you write the program.

I'll try to break the question down for you :

Write a program that uses cin to read a given name (like Louis) and a family name (like Armstrong) into two string variables, given and family. 
//Meaning you have 2 string variables called family and given, and 
//you need to ask the user to input a first name and a last name

The program then makes assignments to two other string variables: givenFirst and givenLast. To givenFirst it assigns the concatenation of given, a space, and family. 
//means that you need 2 other string variables called givenFirst and 
//givenLast. And to givenFirst you need to concatenate or add the 
//string variable given, a space and the string variable family.
//Here is an example : 
string givenFirst = given + " " + family

To givenLast, it assigns the concatenation of family, a comma followed by a space, and given.
//same concept as above, try it out.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

here is statment write c++ statements the include the headerfiles iostraem and string

see i make wrong or right

#include
using namespace std:;( i dont know about std so plz explain)
int main()
{
cout<<"a"<

IT seeker
Light Poster
38 posts since Oct 2009
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You