This program basically asks you to input the digits of you're binary number then converts them into decimal values.The problem was narrowed down to the calculation stage.It used to output wrong values ,ranging from much bigger to just bigger numbers than the needed values but now the program just stops after entry,it doesn't crash or anything just after I finish entry it stays there with no output what so ever and doesn't end,this started happening after I replaced an infinity while loop with a for loop because after a lot of changes I found out that now I can know the start and end points of the required loop so why risking it with an infinity loop right?
Additional information (how exactly the program should work):
It stores the binary digits in an array then afterwards copies them into a different array but backwards so that the digits start from the lowest value (meaning least significant value) then it starts the calculation.
#include<iostream>
usingnamespace std;
int main()
{
int d[10],e[10],anse=1,r,limit;
shortint counterd=0,i,j;
float bind=0;
cout<<"You can now enter the digits of your binary number. End the entry by entering -1"<<endl;
while(1) //Entry stage
{
cin>>d[counterd];
if(d[counterd]==-1)
{
counterd--; //This is because the counter used to count even the entry of -1
break;
}
counterd++;
}
r=counterd; //The counter value is copied to "r" so it decreases while "counterd" is the end of the for loop
limit=r;
for(i=0;i<=counterd;i++) //The digits are flipped so they start from the lowest instead of the highest in another array
{
e[i]=d[r];
r--;
}
for(i=0;i<=limit;i++) //The calculation happens here (mistakes too aparently)
{
for(j=i;j>=0;i--) //This raises 2 to the needed power according to it's position value(from least significant value to most significant value)
anse*=2;
bind+=e[i]*anse; //Multiplies it by the digits as required
}
cout<<bind; //Decimal value answer
return 0;
}