Well i've made a program that asks the decimal number, and puts it in a numberStelsel.
BUt my problem is that it doenst work properly.
for example
Decimal number = 16
Numberstelsel= 8
I get: 20
This is correct
After i push de Y, to let the program start again.
I insert
Decimal number = 15
Numberstelsel= 5
I get: 20
This is the wrong number + its the same answer of the one before this.
Can someone help me with this one?
Code:#include <stdio.h> #include <conio.h> /* definition of functions: */ int Input(void); void DecimalToBinary(double *); void Output(double); /* variables declare*/ int nDecimal = -1, nStelsel; double dRem , dPow_10 = 1, dBinary; char chAgain = 'y'; int main() { while(chAgain=='y') { nDecimal = Input(); printf("\nVoer het getalstel in:\n"); scanf("%d",&nStelsel); while(nStelsel < 2 || nStelsel >= 10) { printf("Voer een getalstelsel tussen de 1 en de 10:"); scanf("%d", &nStelsel); } DecimalToBinary(&dBinary); Output(dBinary); printf("Do you want to run this program again? [y/n]: "); chAgain = getch(); } /* exit program */ return 0; } int Input(void) /****************************************************| |Function: Hier word het decimale getal gekozen. | |Argument: geen | |return: nDecimal | \****************************************************/ { while((nDecimal < 0) || (nDecimal > 1023)) { printf("Dit programma rekent een decimaal getal om naar een getal \nin de door uw ingevoerde getalstelsel\n"); printf("Your decimal number (0 .. 1023): "); scanf("%d",&nDecimal); } return nDecimal; } void Output(double dBinary) /*******************************************| |Function: Print de waarde uit | |Argument: dBinary | |Return: geen | \*******************************************/ { printf("The value is: %10.0lf\n",dBinary); } void DecimalToBinary(double *pBinary) /*********************************************\ |Function: Rekent het om in het getalstelsel | |Argument: nDecimal | |Return: dBinary | \********************************************* */ { while(nDecimal != 0) { dRem = nDecimal % nStelsel; nDecimal = nDecimal / nStelsel; *pBinary = dBinary + (dRem * dPow_10); dPow_10 = dPow_10 * 10; } }



LinkBack URL
About LinkBacks


