#include <iostream> #include <math.h> using namespace std; void sumNum(){ int a; cin>>a; int sum=0; while (a>0) { int d=a%10; sum+=d; a=a/10; } cout<<sum<<endl; } int main(){ // int b=1; // while (b!=0) // { // sumNum(); // cout<<"You want to exit press 0 continue 1;"; // cin>>b; // } int b; do { sumNum(); cout<<"You want to exit press 0 continue 1;"; cin>>b; } while (b!=0); cout<<"Thanks for coming"; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter