ok here is the thing. I'm working on this easy simple script now for 2 whole days and i decided to get some help before i throw out my laptopt . The thing is it hangs when i enter double numbers. some examples
999
12334
43321
even this one :S 9871234 they all hang
while 987123 (minus the 4) 4321 and 1234 all work. What goes wrong here. If i leave out the aantal[tel]==aantal[tel+1] it al works. I just don't get it. TANX!!! ohw and i'm from holland so therefore the qeard variables . and i have to use the void for the assignment!!!
PS a little other question i know i should use search but i've had it behind this pc for the next day so i would like to know wich program i can use to type C++ and compile. Use windows commands like ctrl-c and ctrl-v and don't have to install. So i put my usb stick in a pc and run it everywhere. I know have turbo C 1 but that's a not user friendly old program :P.
Code:
/*
Door Erwin Gillissen H1IA03
24 december 2005
Input: Positive numbers
Verw.: How much different numbers are there, filter double numbers
Output: Print these different numbers to the screen
*/
# include <iostream.h>
# include <conio.h>
int main()
{
int aantl[30], getal=0, n=0, totaal=0;
aantl[n]=0;
//clrscr();
void volgorde(int aantal[],int&totaal); //subroutine
cout <<"Voer een reeks positieve getallen in:\nEindig met een 0\n";
while (cin >> getal, getal!=0) //end reading with 0
{
if (getal<1) cout << "Voer een getal hoger dan 0 in\n" ; //enter number higher then 0
else aantl[n++]=getal;
}
totaal=n; n=0; //totaal is latest array number
volgorde (aantl, totaal);
//clrscr();
cout << "De volgende "<<totaal<<" verschillende getallen zijn ingevoerd:\n";
while (n<totaal) // print while n is smaller then total
{
cout << aantl [n++] << endl;
}
cin.get();cin.get();
return 0;
}
void volgorde(int aantal[],int&totaal)
{
int gedaan=0,tel=0,hulp=0,correctie=0;
while (gedaan==0)
{
gedaan=1;
while (tel<totaal)
{if (aantal[tel]==aantal[tel+1]) //to filter equal numbers
{
aantal[tel]=0; //the first of the equal numbers gets value 0
gedaan=0; // to enter the first while again when tel equals total
correctie++;
}
else if ((aantal[tel]>aantal[tel+1])||(aantal[tel]==0))//to put numbers in order first double with value 0 gets placed at bottom for later use
{
hulp=aantal[tel];
aantal[tel]=aantal[tel+1];
aantal[++tel]=hulp;
gedaan=0;
}
else tel++;
}
tel=0;
}
totaal=totaal-correctie; //when there was a double number it gets 0 and placed last, with this line it won't get printed later on
}