C++ Help..

Discussion in 'Gaming' started by White B O I, Feb 2, 2009.

  1. White B O I

    White B O I Well-Known Member

    Age:
    34
    Posts:
    813
    Likes Received:
    0
    Joined:
    Apr 11, 2006
    Location:
    Table Town, Arizona
    I'm learning C++ slowly right now,
    and I'm trying to get the user to enter a number, then output it in reversed order
    ex: input 56 output: 65

    here's my code

    Code:
    // 2.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {    
        int i; 
        int reverse(int);
        cout << "Input a number: ";
        cin >> i;
    
        cout << reverse(i);
        return 0;
    }
    don't know why I get an error.
    I'm using Visual Studio 2005
     
  2. AeroSwift

    AeroSwift Member

    Posts:
    19
    Likes Received:
    0
    Joined:
    Jan 17, 2009
    Post error message?
    Post custom header?
    And what the heck is TMain?
     
  3. Prince Zainx

    Prince Zainx The Dark Prince

    Posts:
    10,918
    Likes Received:
    0
    Joined:
    Jun 13, 2005
    Location:
    A world far beyond your imagination...
    I'd love to help you but I suck at C++ or C...only good at Java since well I'm a Java Developer.

    If you want a Java Source Code for that program I'd love to write one but not C..

    Oh and to further help with your problem, I'd suggest you post your error message alongside your header.
    And try renaming your variables a bit more.

    Prince.
     
  4. White B O I

    White B O I Well-Known Member

    Age:
    34
    Posts:
    813
    Likes Received:
    0
    Joined:
    Apr 11, 2006
    Location:
    Table Town, Arizona
    k gimme a min to get the error, on a different comp at the moment, and yes, please do right it in java, couldn't hurt =]

    Code:
    1>------ Build started: Project: 2, Configuration: Debug Win32 ------
    1>Compiling...
    1>stdafx.cpp
    1>Compiling...
    1>2.cpp
    1>Compiling manifest to resources...
    1>Linking...
    1>2.obj : error LNK2019: unresolved external symbol "int __cdecl reverse(int)" (?reverse@@YAHH@Z) referenced in function _wmain
    1>C:\Documents and Settings\Admin\My Documents\Visual Studio 2005\Projects\2\Debug\2.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Documents and Settings\Admin\My Documents\Visual Studio 2005\Projects\2\2\Debug\BuildLog.htm"
    1>2 - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    error window:
    [​IMG]

    IDE: M$ Visual Studio 2005
    anything else that you might need?
     
  5. Bleak

    Bleak Well-Known Member

    Age:
    35
    Posts:
    338
    Likes Received:
    0
    Joined:
    May 3, 2005
    Location:
    Pittsburgh
    Is reverse(int) a function you wrote?

    I would recommend using an input string stream, and just use a string as an input instead of an actual integer.

    That way you can have the size of the number (how many digits are in it) and use that to be able to output each number starting from the end.

    Better yet, use a vector and you can just use the .pop_back() command (to delete the last element) and .back() (to read the last element).
     
  6. .c1

    .c1 Well-Known Member

    Posts:
    824
    Likes Received:
    0
    Joined:
    Aug 5, 2007
    As Bleak said did you write a reverse function or is it built-in
     

Share This Page