Hi I'm pretty new to programming started about 3 months ago, and even though I feel I'm getting better, I still find it not easy at all, I got especially trouble with that code, look I want to put into an array of strings sentences with spaces, etc. At last I found out (ppl on this forum told me how) a way to write whole sentences and keep them complete and not just the first word.But now the problem is that I can't type the first line !!!The second, third,fourth,...X line is okay, but not the first it consistently "jumps" over it WHY?,WHY? and when I use rough integers like 4,5 the problem disappears, and as soon as I replace it with an int variable the problem comes again, I'm desperate please Help exam on monday, very important for me, please try the code and see for yourself and thanks of course the forum has already helped me a lot in these two days.
#include #include using namespace std;
void main(){ void main(){ int NS; string sentence; char charsentence[80]; cout<<"How many sentences ?"<>NS; for(int i=0;i
Did you compile this program? It has "void main" twice. You want "int main" and you only want it once. See my earlier post on your other thread. Is this part of the same problem? You need to flush the input stream after using the >> operator. Stick this line after the line:
cin >> NS;cin.ignore( numeric_limits<streamsize>::max(), '\n' );See this link, particularly post 3: http://www.daniweb.com/forums/thread110008.html
And this link: http://www.daniweb.com/forums/thread90228.html
And again, check out my post in your last thread. If I understand what you're doing, I don't see the need for memset and copy.
http://www.daniweb.com/forums/thread129286.html
I don't recall having to clear the input stream in that thread, but I did in the code you posted.
[EDIT] Just looked at my post in the prior thread and ran it. It does need the above statement and it had a typo in it too. I could have sworn it worked when I posted it, but guess not. Oh well, here's the corrected code:
#include <iostream> #include <string> using namespace std; int main() { int N=0; string *arraystrings2; cout<<"How many sentences ?"<<endl; cin >>N; cin.ignore( numeric_limits<streamsize>::max(), '\n' ); arraystrings2=new string[N]; for(int i=0;i<N;i++) { cout<<"type sentence " << i+1 << ": "; getline(cin,arraystrings2[i]); } for(int i=0;i<N;i++) { cout <<arraystrings2[i]<<endl; } return 0; }