Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,101 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,680 people online right now. Registration is fast and FREE... Join Now!




Any help please on looping

 
Reply to this topicStart new topic

Any help please on looping

jrice528
3 Oct, 2007 - 06:53 PM
Post #1

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 31


My Contributions
Anybody help me with reading a user inputed binary say like 10 would equal 2... I need to go from the first while loop, to the second. I am lost, and dont know what to do. It only reads the first int , how do i move to the second digit in the int?



CODE
#include <iostream>
using namespace std;

int main()
{
unsigned number;
unsigned count= 0;



cout<<"Please enter in a binary number, and I will give you the number ";
cout<< "in decimal form"<<endl;
cin>>number;
while (number=number%10)
{
if (number == 0)
   count = count + 0;
    if(number==1)
            count = count + 1;
break;
}

while(number=number%100)
{
  if (number == 0)
     count = count + 0;
  if (number == 1)
     count = count +2;
     break;
}

cout<<count;


system("pause");
return 0;  
    
}

User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Any Help Please On Looping
3 Oct, 2007 - 07:52 PM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
what exactly are you trying to do at each stage of the algorithm? you need to comment your code to make it clear what each step is (supposed) to be doing.

the start of your first while loop is given by while (number=number%10). this is an assignment expression, not a logical expression - you are assigning the value of number%10 to number. since this is "true", in a way, the loop executes. however, i don't think this is what you mean to do.

please comment the code and explain the intent of the algorithm, in terms of how the routine proceeds through each step.

-jjh
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:56PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month