dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: total beginner with while

  1. #1
    Join Date
    Jan 2016
    Posts
    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,624

    Re: total beginner with while

    Quote Originally Posted by murdoc View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)