Fixed up my code a little bit.

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

86 Replies - 2912 Views - Last Post: 26 February 2018 - 08:26 AM Rate Topic: -----

#16 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 27 January 2018 - 04:41 PM

ndc85430
1 - Because I made I mistake and copy and pasted there before i posted it here. That you for reminding me to remove it.

2 - Yep gonna change the name of the name of the variable. And gonna change the if to 25 from 1.

3 - Do you mean to fuse them in one class? If yes, then my answer is that for now it's not my priority, though I might change that in the future.

4 - About the style things, I like variety thats why I use both, second yep probably gonna change that I did it that way to make if easier to not confuse them.

Also what's wrong with the book I am reading?
Was This Post Helpful? 0
  • +
  • -

#17 jimblumberg   User is online

  • member icon

Reputation: 5535
  • View blog
  • Posts: 17,140
  • Joined: 25-December 09

Re: Fixed up my code a little bit.

Posted 27 January 2018 - 05:52 PM

Quote

Also what's wrong with the book I am reading?


Looking at the table of contents I would say that the problem with that book is that it is teaching C constructs before it even starts to teach about C++ constructs, ie: C-strings and arrays and pointers before even getting near the STL. IMO in modern C++ the STL should be taught earlier, not as an afterthought.

Jim
Was This Post Helpful? 0
  • +
  • -

#18 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 27 January 2018 - 06:09 PM

Well if I read the whole book, it's like two birds with one shot? C and C++
Was This Post Helpful? 0
  • +
  • -

#19 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6327
  • View blog
  • Posts: 21,727
  • Joined: 05-May 12

Re: Fixed up my code a little bit.

Posted 27 January 2018 - 06:29 PM

Almost. Just like there is British English and American English, there is the C way of thinking and doing things, and the C++ way of thinking and doing things. You have to be careful to keep the differences in mind as you design your game architecture.
Was This Post Helpful? 0
  • +
  • -

#20 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,753
  • Joined: 08-August 08

Re: Fixed up my code a little bit.

Posted 27 January 2018 - 06:40 PM

View PostXrey274, on 27 January 2018 - 08:59 AM, said:

I didn't know these functions, more specifically substr().

Do you now know what this function does?
Was This Post Helpful? 0
  • +
  • -

#21 jimblumberg   User is online

  • member icon

Reputation: 5535
  • View blog
  • Posts: 17,140
  • Joined: 25-December 09

Re: Fixed up my code a little bit.

Posted 27 January 2018 - 07:23 PM

Quote

Well if I read the whole book, it's like two birds with one shot? C and C++

Not really, as a beginner you probably don't know what is C and what is C++.

Jim
Was This Post Helpful? 0
  • +
  • -

#22 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 07:54 AM

CTphpbwb Yes I now do, though my explanation might not be the most accurate. Substr()takes a string and with given coordiantes inside the string makes a substring containing what was at these coordinates. The first coordinate is where the string begins and the second is the length of it.
Was This Post Helpful? 0
  • +
  • -

#23 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,753
  • Joined: 08-August 08

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 09:03 AM

Close enough. I'd call the parameters position and length. The manual uses pos and len: http://www.cplusplus.../string/substr/
Was This Post Helpful? 0
  • +
  • -

#24 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 02:38 PM

Also one question if i have cin.get() and I type something it will get transferd to the cin>>variable_name after it. To be more specific I am talking about the beggining of the game. Why does this happen and how can I prevent it?
Was This Post Helpful? 0
  • +
  • -

#25 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,753
  • Joined: 08-August 08

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 02:54 PM

I don't follow you. Look at this code and its result:
	string temp, tmp;
	cout << "Enter a string: ";
	temp = cin.get();
	cin >> tmp;

	cout << "temp: " << temp << endl;
	cout << "tmp: " << tmp << endl;


Enter a string: abcde
temp: a
tmp: bcde
Was This Post Helpful? 0
  • +
  • -

#26 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 03:11 PM

I see. Ok thanks.
Was This Post Helpful? 0
  • +
  • -

#27 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 04:03 PM

Just realised that it still doesn't work. When you are at cin.get() type something that is longer than a single character and you'll see.
Was This Post Helpful? 0
  • +
  • -

#28 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,753
  • Joined: 08-August 08

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 04:11 PM

Still don't know what you mean. Look at my code and my output. I did type more than one character, and cin.get() retrieved the first one, as expected. Maybe you should post code demonstrating the problem you're having.
Was This Post Helpful? 0
  • +
  • -

#29 Xrey274   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 241
  • Joined: 10-December 16

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 06:20 PM

what happens for me is that cin.get() retrieves the first character then cin>> is skipped and inside the string is placed the thing i typed on cin.get() without the first character.

Example:

At cin.get() I type "smart"

after cin.get() I have cin>>word;
it skips the cin>>word; and just displays the output
cout<<"The word you typed is: "<<word; - The word you typed is mart
Was This Post Helpful? 0
  • +
  • -

#30 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3798
  • View blog
  • Posts: 13,753
  • Joined: 08-August 08

Re: Fixed up my code a little bit.

Posted 28 January 2018 - 06:44 PM

How is that not expected behavior? It's doing just what my code does: getting the first character.
Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »