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;
}
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;
}
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.
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?
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
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.