0

Thanks WaltP that second one i was just kind of assuming i knew it was a class but i didnt know it was an array managed by a class thanks again.
Which code anthony?

sorry hag++ it was originally a char array but i was trying to move it to a string. i thought maybe he would like the .length() part.

Edited by Anarionist: I made yet another boo boo

0

finally got it you guys thank you so much. I needed the << in between the line[4] and line[3] etc. I know it's probably the long way around but I'll get better at i go along. But thanks so much glad I found you guys.

0

Thanks WaltP that second one i was just kind of assuming i knew it was a class but i didnt know it was an array managed by a class thanks again.
Which code anthony?

sorry hag++ it was originally a char array but i was trying to move it to a string.

Yea i know, the way both you and I had it before (i.e using char array) is quick and does the job for this project..... using strings is nice but not needed but somehow everyone started to veer towards using strings instead lol

0

Is there a specific reason that you are using a string instead of char array? It would be easiest with an array because of how you can manipulate it

Having to know how many chars you need ahead of time is a biggie. I think strings behave a bit better with cin than char arrays. If he/she was already using strings in his code he/she should continue using them.

0

no problem :P if you need any more help ask me i have a skype if you want to chat in real time about anything. or you can email me at [snipped]
sorry waltp but it and my third email are already spammed to death besides there is a 2% chance of me catching anything ubuntu/debian is pretty much bulletproof (im not saying its invulrnebable but its unlikely) and its is my spam account its been every where from bf-committer(blender3d dev forum) to here and who knows where else.

Edited by Anarionist: Never post an email address on a forum. Wanna get spammed to death?

0

finally got it you guys thank you so much. I needed the << in between the line[4] and line[3] etc. I know it's probably the long way around but I'll get better at i go along. But thanks so much glad I found you guys.

In my opinion, you should create a new copy of the reversed string then output it, not just output the original char by char backwords. You learn more that way.

Also, please post your final code. We'd like to see how it finally ended up.

0

no problem :P if you need any more help ask me i have a skype if you want to chat in real time about anything. or you can email me at [email]snipped[/email]

Sounds good :cool: Right back at ya

0

lol but in seriousness if you need help im not sure if this site has pm i just joined but if it does feel free to use it.

0

I think strings behave a bit better with cin than char arrays.

I'm not so sure about that... They seem to be pretty much the same to me.

If he/she was already using strings in his code he/she should continue using them.

Very true...

Is there a specific reason that you are using a string instead of char array? It would be easiest with an array because of how you can manipulate it

using strings is nice but not needed but somehow everyone started to veer towards using strings instead lol

Probably because in C++ char arrays are necessary at times, but strings are somewhat more standard and have more functions(methods) to deal with them easier. They are also dynamic. As for this type of manipulation, either string or char array is just as simple.

0

lol but in seriousness if you need help im not sure if this site has pm i just joined but if it does feel free to use it.

No.... Please post in the forums. The idea here is for everyone to learn, not have little discussion groups behind the scenes.

0

here is the final code still writting i have to write a sentence and write a phrase that will count the words, but i don't know how to do that either

//This program will utilize the String Length, Backward String, and the Word Count.
#include <iostream>
#include <string>
using namespace std;



int main()

{
	string city;  //to hold the city input
	string line;
	const int size=80; // array size
	char Phrase[size];   //to hold the sentence
	int count= 0;
	


	//Ask the user what city they were born in.
	cout<< " What city were you born in?\n";
	cout<<" ";cin>> city;

	//Tell the user how many letter are in the city they were born.

	cout<<" There are " << city.length() ;
	cout<< " letters in you city's name.\n";
	cout<<"\n";

	//Ask the user to enter a phrase
	cout<<" Please enter a word no more than 5 letters and I\n";
	cout<<" will display it backwards.\n";
	cout<<" ";cin>> line;

	//Display the line they entered backwards
	cout<<" Here is the word you entered backwards.\n";
	cout<<line[4]<<line[3]<<line[2]<<line[1]<<line[0]<<endl;

	//Get the user to enter a sentence
	cout<<" Please enter a sentence.\n";
	cin>> Phrase;

	

	


	return 0;
}
0

very nice OP very nice i like your whitespace its better than some that i have seen. as for the word counting the only thing i know to do is to create a function to parse the string input and when it finds a whitespace add 1 to int x;
i would code this but atm im to tired to think clearly time here is 12:54 am.
nite ill probably be on tommorrow round same time.
sorry messed up and put own where on was lol.

Edited by Anarionist: n/a

0

I'm not so sure about that... They seem to be pretty much the same to me.

I meant strings as more well behaved with cin >> but I didn't clarify that. Apologies.

Probably because in C++ char arrays are necessary at times, but strings are somewhat more standard and have more functions(methods) to deal with them easier. They are also dynamic.

Well put.

Edited by jonsca: n/a

0

here is the final code still writting i have to write a sentence and write a phrase that will count the words, but i don't know how to do that either

Well, think about what you are trying to accomplish -- what is a word, what is a sentence, things like that. And write TEST code to see how cin really works when reading letters, words, sentences. It will be an eye opening experience, and you will be surprised what you're going to find out.

Now, for your code:

//Ask the user to enter a phrase
	cout<<" Please enter a word no more than 5 letters and I\n";
	cout<<" will display it backwards.\n";
	cout<<" ";cin>> line;

	//Display the line they entered backwards
	cout<<" Here is the word you entered backwards.\n";
	cout<<line[4]<<line[3]<<line[2]<<line[1]<<line[0]<<endl;

That's your solution? Sorry, but with all the help we've tried to give you, it's really lame. And I hope it's not what your instructor wants.
Post #7 by you kind of states one thing, and I concurred in post #36. Then you wimped out.... :icon_wink:

0

Well, think about what you are trying to accomplish -- what is a word, what is a sentence, things like that. And write TEST code to see how cin really works when reading letters, words, sentences. It will be an eye opening experience, and you will be surprised what you're going to find out.

Now, for your code:

//Ask the user to enter a phrase
	cout<<" Please enter a word no more than 5 letters and I\n";
	cout<<" will display it backwards.\n";
	cout<<" ";cin>> line;

	//Display the line they entered backwards
	cout<<" Here is the word you entered backwards.\n";
	cout<<line[4]<<line[3]<<line[2]<<line[1]<<line[0]<<endl;

That's your solution? Sorry, but with all the help we've tried to give you, it's really lame. And I hope it's not what your instructor wants.
Post #7 by you kind of states one thing, and I concurred in post #36. Then you wimped out.... :icon_wink:

That was the only one that I could really understand. I am taking this class online so we really have to read the book and teach ourselves. I have been reading so of the material from programming one to catch up. Sorry it probably was kinda lame. I will get better as I go one. I never give up. Thanks for your help and honesty. I really need it to get better. Thanks Walt.

0

That was the only one that I could really understand. I am taking this class online so we really have to read the book and teach ourselves. I have been reading so of the material from programming one to catch up. Sorry it probably was kinda lame. I will get better as I go one. I never give up. Thanks for your help and honesty. I really need it to get better. Thanks Walt.

Online prog classes?? Ouch! That is not such a great idea to be honest with you. A lot of classes are well suited for teach self/ online learning but I dont think programming is one of them. Having an instructor in front of you to give you visual examples and the biggest thing, the other students around you (asking questions and being totally lost with you hehe) is a BIG part of the learning experience...... just my opinion tho =) The second thing, I would have to agree with WaltP about your final code. I know you are just learning but now is the time to get it right because it will carry over to ALL your work in the future. The reason we don't like it is because it is not flexible at all. What if the user enters a string that is only 2 characters long? What if they enter 20?

Finally, this line in your code:

//Get the user to enter a sentence
	cout<<" Please enter a sentence.\n";
	cin>> Phrase;

Remember the rules of cin. If the user enters a sentence, it will have spaces in it. Does cin read or ignore spaces?

Edited by hag++: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.