Welcome to Dream.In.Code
Become a C++ Expert!

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




base conversion~plz help me~ i need to handhi tomor.

 
Reply to this topicStart new topic

base conversion~plz help me~ i need to handhi tomor.

vole
20 Mar, 2007 - 06:01 AM
Post #1

New D.I.C Head
*

Joined: 7 Mar, 2007
Posts: 4


My Contributions
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define LENGTH 20
main()
{
CODE
char num[LENGTH];
         int i, temp, base10, baseN, j;
         printf("Enter a number and baseN:");
         scanf("%s%d",&num,baseN);


[/CODE]if( baseN >= 2)[/CODE]{ // ensure the base is larger than 1
CODE
for ( i=0; i<strlen(num)-1; i++)
// check the length of
string, in fact , i don't know why i wirte it

*line14
CODE
temp = num[i]; // change the position of num
         num[i] = num[LENGTH]; // same
         num[LENGTH]= temp; // same
         for ( j=0; j<=strlen(num); i++)
// actually i don't know what
i do

CODE
base10 = 0;
         base10 = base10 + ((num[LENGTH] * baseN)+ num[i]+1);

// find
the num of base10
printf("base10 = %d\n",base10);
system("PAUSE");


}
}


At line14, actually i want to eg..
1011(2)-----> 1*2^3+ 0*2^2+ 1*2^1+ 1*2^0---> 1*2^0+ 1*2^1+ 0*2^2+
1*2^3

and for this (((a * X) + cool.gif * X) + c
i am not really understand how to write it

can anybody help me to complete the programe
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Base Conversion~plz Help Me~ I Need To Handhi Tomor.
20 Mar, 2007 - 07:04 AM
Post #2

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
The for loop can just be:
CODE

  for (i = 0; i < LENGTH; i++)


because the array is
num[0], num[1], ... , num[LENGTH - 1]
for an array that is LENGTH long.

So i increments as: 0, 1, 2, ... (LENGTH - 1) in the loop described above.

User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Base Conversion~plz Help Me~ I Need To Handhi Tomor.
20 Mar, 2007 - 07:11 AM
Post #3

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
What is the program supposed to do? It appears to be attemting to convert letters to a custom base numbers, but your description seems to be some kind of polynumeral.
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Base Conversion~plz Help Me~ I Need To Handhi Tomor.
21 Mar, 2007 - 09:40 PM
Post #4

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
Here is a program that does this.

http://www.dreamincode.net/code/snippet903.htm
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:57PM

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