-
January 24th, 2016, 01:10 PM
#1
total beginner with while
Hey, can you help me with this? I know I should add more variables but I still dont know where. You are given a number and you have to find the sum of the numbers that consist of that number, for ex. if you are given 177, the answer should be 15. I know it's pretty easy but I still can't crack this. I dont know how to complete the division part.
#include <iostream>
using namespace std;
int main (){
float n=1, sum=0; // n-number(that will be given)
while(n>0){
cin>>n;
n=n%100;
n=n/ ; //???
sum=sum+n;
}
cout<<sum;
return 0;
Edit & Run
-
January 24th, 2016, 02:01 PM
#2
Re: total beginner with while
Originally Posted by murdoc
Hey, can you help me with this? I know I should add more variables but I still dont know where. You are given a number and you have to find the sum of the numbers that consist of that number, for ex. if you are given 177, the answer should be 15. I know it's pretty easy but I still can't crack this. I dont know how to complete the division part.
Then first take a piece of paper with a pencil and try to write on the paper (!) how you will do it.
Besides, please read the Announcement: Before you post....
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|