Click to See Complete Forum and Search --> : need help developing an algorithm for this .


JERRYBOY78
October 30th, 2006, 09:28 PM
develop a base conversion calculator program which converts a positive integer number (Num) from a given base (sourceBase) to an alternative base (targetBase), where sourceBase and targetBase are integer values ranging between 2 and 10 inclusive. The program should only perform the conversion if the user enters a valid source base number, otherwise an appropriate alert message should be posted.



thanx in advance for your help.

Yves M
October 31st, 2006, 01:29 PM
What code do you have so far? (you may want to read this first (http://www.codeguru.com/forum/showthread.php?t=366302))

JERRYBOY78
November 2nd, 2006, 12:02 AM
this is as far as i've gotten::


#include <stdio.h>

int main()
{
int num1;
int base1;
int rem;
int quo;

printf("please enter a value for num1 and a target base1 number.");
scanf("%d", num1, base1);
if num1 < base1
{
printf("the number must be positive......GOODBYEEEEE!!!!!!");
}
else
{
quo = num1 / base1;
rem = num1 mod base1 / base1;

}
if quo = 0
{
printf("%d", rem);
}
else
{
while quo != 0
{
printf("%d", rem)
}
rem = the remainder of quo / base1
quo = the remainder of quo / base1

end while
printf( "%d", rem )
end if
end if
end

return o;

}

StreamKid
November 4th, 2006, 10:08 AM
(1) scanf("%d", num1, base1);
->argument(s)
pointer to objects or structures to be filled with data read as specified by format string. There must be the same number of these parameters than the number of format tags.
NOTE: These arguments must be pointers: if you want to store the result of a scanf operation on a standard variable you should precede it with the reference operator, i.e. an ampersand sign (&), like in:

int n;
scanf ("%d",&n);
(ref)http://cplusplus.com/ref/cstdio/scanf.html
so, write it like: scanf("%d", &num1, &base1);

(2)else
{
while quo != 0
{
printf("%d", rem)
}
->if once, the while will be for ever true, since nothing changes. perhaps you should put the ending bracket after the two following statements?

JERRYBOY78
November 4th, 2006, 01:22 PM
thanks alot streamkid. your help & advice is greatly appreciated.