Simple poker code

This is a discussion on Simple poker code within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by got1sleeve My teacher must have confused me then. I originally had the & in there and he ...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by got1sleeve View Post
    My teacher must have confused me then. I originally had the & in there and he said strings are pass by reference so i didn't need them in there and thats why they were causing the link error.
    There's a difference here between C-style strings and C++ std::strings. A C-style string is an array of characters, so it gets passed to a function as a pointer (which, in C, is as close as we get to pass-by-reference). A C++ string is a single type (not an array), so it needs to be passed by reference (using &) if we want changes to be seen in the main program.

  2. #17
    Registered User
    Join Date
    Jan 2008
    Posts
    25
    well I struggle with c++ let alone know anything about c haha i stick to this forum....but any suggestions as to why the code doesn't output anything?

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    Let's fire up the debugger!
    EDIT:

    Duh! Of course!
    Code:
    	int ansr;
    
    	cout << "\n\nTo deal yourself a poker hand please press D. " ;
    	cin >> ansr;
    You're reading a string or a char into an int. Ansr must be a char.
    You can also remove n from the function because you aren't using it.

    Also, in get card:
    Code:
          default:
            val=value;
    Apparently, you get an implicit conversion from int to char here, so you might as well do an explicit conversion by doing a cast and silencing a warning.
    Last edited by Elysia; 01-31-2008 at 03:55 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 11-23-2005, 07:53 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  4. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 10:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21