The program works but it keeps going and going. I don't know how to stop it. Can anyone advise me on how to do this?
// Program to split integer into its seperate digits
#include <iostream>
using namespace std;
int main()
{
while ( 1234 > 0)
{
int digit1 = 1234%10;
int digit2 = 1234/ 10%10;
int digit3 = 1234/ 100%10;
int digit4 = 1234/ 1000%10;
cout<< digit1 <<endl;
cout<< digit2 <<endl;
cout<< digit3 <<endl;
cout<< digit4 <<endl;
}
return (0);
}
you could add a break statement as an if statement condition if you need to.
Thanks for your help. Had to do it with a while for the question.