Thread: Turbo C++ help. Computer Interaction

  1. #1
    Registered User
    Join Date
    Aug 2008

    Question Turbo C++ help. Computer Interaction

    hello everyone, i'm a college student and am starting to tackle C++
    i'm supposed to create a program that looks like the computer is talking to the user. here is my source code:

    /*Computer AI*/
    #include <stdio.h>
    #include <conio.h>
    {/*start of program*/
    int age;
    char nickname[10];
    printf ("What's your name?");
    scanf ("%s", &nickname);
    printf ("Hello %s.", &nickname);
    printf ("\nHow old are you?");
    scanf ("%d", &age);
    printf ("you're %d yrs old?", &age);
    every time i run the program -12 always shows as the age why is that??
    please help thanks!!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    printf ("you're %d yrs old?", &age);
    Is incorrect, you are printing the ADDRESS of age, not the value of age.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    The larch
    Join Date
    May 2006
    When you print things, you pass values to printf, not pointers.

    When you input strings with scanf, you shouldn't pass a pointer to pointer (don't take the address of the string).

    By the way, this is nothing but antiquated, non-standard C. There is absolutely no C++ code here.

    In C++ this code would be:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
        int age;
        string nickname;
        cout << "What's your name? ";
        cin >> nickname;
        cout << "Hello " << nickname << ".";
        cout << "\nHow old are you? ";
        cin >> age;
        cout << "you're " << age << " yrs old?";
        return 0;
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    If you can, I also do suggest you dump Turbo C/C++, because it's old and not very standards compliant.
    Some good alternatives:
    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.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    i'm supposed to create a program that looks like the computer is talking to the user.
    Many years ago I had a copy of ELIZA and the BASIC source code... It was kind-of fun to "play with" at first, then it would get annoying... Ond one of my coworkers discovered that it would react to foul language!

    It's a little advanced for an absolute beginner-programmer, but it's something you could handle by the end of your first semester. I don't remember exactly, but the version I had was something like several-hundred lines (or maybe a few thousand lines) of BASIC... not an overwhelming amount of code, and nothing too complex... Mostly just a bunch of "if-statements". For example, if the user types in "mother" or "father", ask something about parents or family, etc.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    The very first thing you can do is ditch Turbo C++. It's far too old to be used as a modern compiler.

  7. #7
    Registered User
    Join Date
    Dec 2007
    And yet a whole subcontinent -- at least -- of users are being taught on TC.

  8. #8
    Registered User
    Join Date
    Aug 2008
    Quote Originally Posted by Bubba View Post
    The very first thing you can do is ditch Turbo C++. It's far too old to be used as a modern compiler.
    +1 for that! There are at least two free compilers with great IDEs (in my opinion): Dev-c++ is a free download, version Macrosoft is giving away Visual c++ Express for the mere trouble of registering with them. I got both of these in the last couple of weeks, and they're better than what I remember of Turbo c++... which is, admittedly, long ago.

    Does Turbo c++ still use all the conio console i/o? If they do, and if you're just determined to use it, there was a good book called the Turbo C Survival Guide. It was out of print ten years ago... but might be around in some used bookstore.

    Bubba's right!

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    TC++ relies on a real-mode environment which on Windows XP is simulated at best and completely different at it's worst. Some things you used to be able to do in TC++ you can no longer do b/c of XP. You are programming in an environment that is both unreliable and unsupported.

    There is NO excuse to use TC++ when Microsoft Visual C++ Express Edition is available and when Microsoft offers discounts to uni's for MSVS Standard. Every school out there that wants to teach C++ should at least have MSVS standard. MSVS runs under Windows and is in a 32-bit protected mode environment. It supports multi-threading, the STL, templates, and a whole lot more that TC++ doesn't have. Not to mention that most businesses out there will either have MSVS or some other 32-bit PM IDE that runs under Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Computer Scientists and Hacking
    By TheDan in forum A Brief History of
    Replies: 7
    Last Post: 12-04-2006, 09:44 PM
  2. Regarding Undergraduate Computer Majors
    By UnregdRegd in forum A Brief History of
    Replies: 11
    Last Post: 10-04-2003, 11:55 AM
  3. Problems shutting off computer
    By frenchfry164 in forum Tech Board
    Replies: 9
    Last Post: 04-22-2003, 06:19 PM
  4. Computer engineering - programming.
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 07-15-2002, 02:37 PM
  5. computer sex
    By Unregistered in forum A Brief History of
    Replies: 5
    Last Post: 09-17-2001, 07:09 PM

Tags for this Thread