The following code does everthing required except that because each numeral of the integer has to be entered individually the numbers appear in a vertical column. Question: is there a way of entering the numbers so that they appear on the screen in one row each having been entered individually?
Code:
int main ()
{
string s;
char c;
int sum=0,n=0,a[6]={0},num=0;
cout<<"Enter a 6 digit integer \n";
int i=0, fact=100000;
while(i<6)
{cin>>n;
a[i]=n;
num+=a[i]*fact;
fact/=10;
i++;
if(i>5) break;
}
cout<<"The integer entered is: "<<num;
if(num%3==0)cout<<" and is divisible by 3 (= "<<num/3<<" )";
else cout<<" and is not divisible by 3";
for(int i;i<6;i++)
sum+=a[i];
cout<<"\nSum of numerals is: "<<sum;
if(sum%3==0)cout<<" and is divisible by 3\n";
else cout<<" and is not divisible by 3\n";
cout<<"\n";
system("pause");
return 0;
}
Comment