+ 2
Where i am going wrong help
#include <iostream> using namespace std; int main() { int n,r,sum=0; cout<<"Enter a number "; cin>>n; while (n>0){ r=n%10; sum=sum+n; n=n/10; } cout<<"\nthe sum of your digit is:"<<sum; return 0; }
2 Réponses
+ 3
sum=sum+n <-- should be r not n if you want the sum of the digits.
+ 3
Oh my bad Thank you by the way