problem >dizzy me<

// From any base from(2:9) To Decimal.
#include <iostream>
using namespace std;

int main()
{
char arry[100];
int i,b,Quotient=0,decimal,counter=0,bit;

cout<<"Enter Base Number :";
cin>>b;
cout<<"\n Enter Bits of number : ";
cin>>bit;
cout<<"\n Enter number : ";
for(int i=0;i<100;i++)
{
cin>>arry[i];
counter++;
if(counter==bit ) // program come to here and don't complete.
break;
}
decimal=Quotient*b+arry[i]; // i have warning here.
while( i>=0 );
{
decimal=decimal*b+arry[--i];
}

cout<<"\nDecimal Number is :"<<decimal;
return 0;
}


I Hope Someone Get Solution Soon
and Write The Correct Code.
Last edited on
one problem is that you declare int i 2 times, one in the if statement.

and this
decimal=Quotient*b+arry[i];
it's out of if statement , and the previous i is not initialized.

and the char array, last position must be a '\0'.
Last edited on
#include <iostream>
using namespace std;

int main()
{
char arry[100];
int j=0,i,b,Quotient=0,decimal,counter=0,bit;

cout<<"Enter Base Number :";
cin>>b;
cout<<"\n Enter Bits of number : ";
cin>>bit;
cout<<"\n Enter number : ";
for(i=0;i<100;i++)
{
cin>>arry[i];
counter++;
if(counter==bit )
break;
}

decimal=Quotient*b+arry[j];

{
decimal=decimal*b+arry[++j];
}

cout<<"\nDecimal Number is :"<<decimal;
return 0;
}


i fixed it to this code but didn't give correct answer
any help :)
Last edited on
closed account (3qX21hU5)
Please use codetags when posting code to the forum (Highlight your code and click the <> button under format) it makes it much easier to read the code you post.

Also what is your question exactly? You say its not giving you the correct answer but what is the correct answer? What is your program suppose to do? What are you having trouble understanding? Please be detailed about the problems you encounter when you post a question :).

One thing I noticed just off the bat without knowing what problems you are experiencing is this

1
2
3
    {
        decimal=decimal*b+arry[++j];
    }


Why do you have them brackets there?

Also

int j=0,i,b,Quotient=0,decimal,counter=0,bit;
Is very hard to read. It is better to have them each on their own line when you are assigning to them.

1
2
3
int j = 0;
int Quotient = 0;
int counter = 0;


Also make sure you are using the same style consistently. By this I mean notice how one of the them variable names starts with a uppercase letter and all the others don't? It seems very minor but it will actually cause a lot of confusion later.

But anyways them are just minor things, so let us know what exactly your problem is and we will do our best to help guide you in the right direction (We won't just give you the code ;p).
Last edited on
My Code Used For

Change number from(base 2,base 3...To base 9) to give number in base 10=(decimal)

ex:
if u enter number 1352 base 8 give u number 746 in decimal.

My program is based one 2 line
decimal=Quotient*b+arry[j]; u may change this for decimal=arry[j]
>> i used j to take first number in array that will be 1 in ex. <<
decimal=decimal*b+arry[++j];

i hope u answer me again :)

and i think char arry[] should be int arry[] but not give correct answer. :)
Last edited on
Topic archived. No new replies allowed.