My code is not working

sir i have written same code as taught in the video lecture and it’s not working

@Anku47
Please save your code at ide.codingblocks.com and share link here. I’ll check

#include
using namespace std;
int main(){
int n;
cin>>n;
int sum=0;
while (n>0){
int last_digit=n%10;
sum = sum + last_digit;
n=n/10;
cout<<“sum of digits”<<sum<<endl;
return 0;
}

}

@Anku47
You have wrote cout<<“sum of digits”<<sum,endl; and return 0; inside while() loop.
These two line should be outside the scope of while() loop. Cut them and paste them outside while loop.

1 Like

@Anku47
mark this doubt as resolved if you got the logic.