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
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.
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: IDE: M$ Visual Studio 2005 anything else that you might need?
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).