Please help

i'm new to this program C++.
write a program that reads an integer and breaks it into a sequence of individual digits. for example the input 16384 is displayed as 1 6 3 8 4.

please help me edit and add some code to this.
Thanks a lot.

#include <iostream>
#include <string>

using namespace std;

int main()
{
cout << "Enter a five-digit number: ";
cin >> number;

cout << number / 10000 << " ";
number = number % 10000;
cout << number / 1000 << " ";
number = number % 1000;
cout << number / 100 << " ";
number = number % 100;
cout << number / 10 << " ";
number = number % 10;
cout << number << endl;
return 0;
}
please help me edit and add some code to this.


What else do you need?

Once you define number it looks like it would work.
When I compile it came out with errors. Do I need to replace 'number' with a five-digit numbers?
No, you need to define "number".
Any outcomes will help me? Please show me how? I'm new to this program. Thanks
The compiler needs to be told that 'number' is a variable (in this case an integer)

To do this, put int number; before cout << "Enter a five-digit number: "; so that int main () now looks like this:

1
2
3
4
int main ()
{
    int number;
    cout << "Enter  
and then the program goes just as you posted it.

For more information, look at this article: http://cplusplus.com/doc/tutorial/variables/
Thank you very much, I appreciate your help. I hope I can have better professor for this course, instead of reading outline from textbook' author. :)
Theranga, why does it say an error when I tried to compile it?
@nhat nguyen

include
int number
and it works. Which kind of error do you get? Can you post the whole code? You may missing or misspelling something?
here is my code, i dont know it has fatal error when i run on Microsoft Visual C++. but here is what ideone.com reported: input: no output: Enter a five-digit number: -121762 -6 -1 -2 -4

how do i correct code that fitted to the question posted above: write a program that reads an integer and breaks it into a sequence of individual digits. for example the input 16384 is displayed as 1 6 3 8 4.


#include <iostream>
#include <string>

using namespace std;

int main()
{
int number;
cout << "Enter a five-digit number: ";
cin >> number;

cout << number / 10000 << " ";
number = number % 10000;
cout << number / 1000 << " ";
number = number % 1000;
cout << number / 100 << " ";
number = number % 100;
cout << number / 10 << " ";
number = number % 10;
cout << number << endl;
return 0;
}



thank you very much for all helps
The problem has nothing to do with the code. I've tested and it works properly. You can submit the code. My advice to you is to create a new project and copy the code and paste it.
Can you post the error that you getting?
Thanks a lot Bandar, I will
here is code from Visual C++.

1>------ Build started: Project: 1, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>c:\users\n\documents\visual studio 2010\Projects\1\Debug\1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

and from ideone.com was reported:
input: no , output: Enter a five-digit number: -121762 -6 -1 -2 -4. eventhough i didnt put any value of number. hows this come out?
Does this error exist only in this project?
I think it happened to my some previous problems, after Ihave got advices from others. That's why I double check via ideone.com website. What did you get when u help me run this code?
@nhat nguyen
I've got what you're looking for. I'm using Qt in mac though. If this not a new problem then you may have problem with visual studio 2010. I can't say for sure since the code works properly.
If you are using Visual Studio, when you create a new project, create a new Blank Project or it will assume you want to program using Microsoft's version of C++
Make sure that when you are creating a new project that it is a console program and that you click on c++ not c#. You can also try
int number = 0;

let me know if that works
Last edited on
Turtle wrote:
Make sure that when you are creating a new project that it is a console program
This is wrong - it forces you to use a different kind of main function and it also forces you to use the very ugly stdafx.h which causes so many people trouble. Create a new Blank Project, not a Console Project.
Topic archived. No new replies allowed.