Please help out me to correct this program please.

Write a program that takes a four digits integer from user and shows the digits on the
screen separately i.e. if user enters 7531, it displays 7,5,3,1 separately.


#include <iostream>

using namespace std;

int main()

{
//declare variables
int number, digit;

digit=1234;

//prompt the user for input
cout <<"Please enter the 4-digit number: ";
cin >> number;

//get the first digit and disply it on screen
digit= number%10;
cout <<"The Digits are: ";
cout <<digit<<" ";

//get the remaining three digits number

number = number % 10

//get the next digit and display it
digit= number%10;
cout <<digit<<" ";

//get tje mext two digit number

number=number%10

//get the next digit and display it
digit= number%10;
cout <<digit<<" ";

//get the reamaining one digit number

number=number%10;

//get the next digit and disply it
digit=number%10
cout <<digit;



}


You're doing the wrong thing.

1
2
3
4
digit=1234;

//get the first digit and disply it on screen
digit= number%10;


that gets 4, not 1. Right? You need a way to get the 1 and isn't restricted to 4 digit numbers.
Please explain it more
Topic archived. No new replies allowed.