adityatandon 23 Junior Poster in Training

No idea... I've got A Dual Core Processor and a 2 GB Ram and was able to play the game without a problem... Switch off all unnecessary things.. Like for example : The windows sidebar.. Thats a pain.. takes up unnecessary ram space.. Switch of all downloads.. Web browsers, music players etc.. If none of this works.. There could be a problem with your computer overheating.. and the RAM not being cooled too fast... Used to happen to me sometimes when my computer would just suddenly switch off.. Figured out that was a problem of overheating of the system.. The fan had stopped working.. The computer does that automatically to prevent spoilage of hardware.... For how many hours do u run ur system in a day ?

adityatandon 23 Junior Poster in Training

Yeah, i had the same problem... The solution i found to it, that is without using dynamic allocation, is writing all my data down into a separate file.. And then sorting the elements in the file by using functions like seekg() and tellg(). And after which u can read out the median.

adityatandon 23 Junior Poster in Training

Yup... agree with him.. When u use srand, irrespective of when u run the program and when it isnt initialised with a random variable at any time, it will always generate the same set of random numbers... Run it at 4:00 Am, it'll probably generate 4,7,8,3,2.. Run it at 4:01 am, the same thing.. in the same sequence.. At 5:00 pm 4 days later.. the same thing... Not so random are they then ?

adityatandon 23 Junior Poster in Training

Thats because u put the value of a[2] into a[1] thats why. Luk at ur 3rd statement...
If u put a[1] = a[0] and then print a[0] and a[1], ur output will be 1.1 1.1 !! I think u shud read up on arrays !!

adityatandon 23 Junior Poster in Training

It isn't something of bad or good than necessity.. I used to think writing all the function definitions of the class is better as it saves me time, space and effort.. Yes that is true only when u are making a small program.. When u start making a program which tends to a complete software often comprising 5000+ lines, u realise its crazy when everything is inside the class itself.. So, like said earlier too, its more of whats right for you and when and not whether it should be done or not !! Preferably, its better to separate it..

@ Mike,
That was quite a mouthfull :P Btw, gr8 qualifications.. B.Eng., M.Sc., M.Sc.(Tech.), PhD candidate in Aerospace Robotics.. I must say, VERY impressive !!

adityatandon 23 Junior Poster in Training
adityatandon 23 Junior Poster in Training

Yeah... but just using the code i gave above is a substitute for all of it..
Isupper resides in the standard library with the same procedure u mentioned here.. Why write the whole code, when there already exists a direct function for it ??

adityatandon 23 Junior Poster in Training
int j=0;
for(int i=0;i<26;++i)
if(isupper(string[i])==1)
j+=1;
adityatandon 23 Junior Poster in Training

Umm..nope... what u can do is while running, u store the prime numbers found in an array and keep checking whether the number is a multiple of any of the primes above 10!! Surely that'd decrease processing speed.. but its worth it !
Also, what u could try is.. to check whether a number is prime or not, the following code can be used :

#
#           // Include necessary headers
# 

int main()
{clrscr();
int n,flag=1,numbr;
cout<<"Enter the number to be checked ";
cin>>n;

for(int i=1;i<n/2;++i)
    { if(n%i==0)
        {flag=0;
         numbr=i;
         break;
        }
     }

if(flag==0)
cout<<"As "<<n<<" is divisible by "<<numbr<<"it is not a prime number";

if(flag==1)
cout<<n<<" is a prime number";

return 0;
}

But yes, this increases run time !!

adityatandon 23 Junior Poster in Training

Hehe.. the sieve of erasthones is nice, but its utilising the same thing i posted in an earlier post..!! That is, if your number is indivisible by the numbers below 10, then it is 90% a prime number !!

P.S - This stands true for all numbers that are odd multiples of prime numbers

Eg: 169 = 13 x 13 ( 13 is a prime, yet 169 is indivisible by numbers below 10)

adityatandon 23 Junior Poster in Training

Your welcome :)

Agouri commented: Helpful links +0
adityatandon 23 Junior Poster in Training

You are on the right track as LRRR said.. As already pointed out earlier by me and then again by LRRR, reason randindex wasnt double was because u wer calling elements of an array! Coming to checking for doubles, u are going correct but instead of so many ifs and elses, use the following :

for(int i=0;i<26;++i)
         { for( int j=0;j<26;++j)
                { if(cboxvalue[i]==cboxvalue[j])
                     cboxvalue[j]=0;
                 }
          }

What the above loop is doing, is comparing all elements and if any element is repeated, it just converts it to 0 and hence u can later search for the 0's and replace them with numbers that are not 0's and are not repeated !

adityatandon 23 Junior Poster in Training

Agree with LRRR !! What the hell dya require 10000 for ?? Since wen did names get so big? And u do realise you just wasted a load of ram space.. Reserving 10000 for city and name - The char size depends from system to system and is a minimum of 1 byte.. So u just wasted 2 x 10000 = 20,000 bytes or close to 19Kb for nothing...

Coming to ur problem :
Its still that u havent defined the stream...Use any of the following :

ofstream infile("D:\\muqeet.txt");
 
           //OR

fstream infile;
infile.open("D:\\mugeet.txt",ios::out);
adityatandon 23 Junior Poster in Training

Well... that is one option or you could alternate between printing and writing blank spaces over the written text ( like clrscr(), bt not using it ) with a delay command in the middle...

You can keep doing that in a while loop until u press enter! Example code below :

#include<iostream.h>
#include<conio.h>
#include<dos.h>

void main()
{ while(getche()!='\r')
     { gotoxy(24,10);
       cout<<"Press Enter Key To Begin";
       delay(300);
       gotoxy(24,12);
       cout<<"                          ";
      }
}
adityatandon 23 Junior Poster in Training

Program Worked ?

adityatandon 23 Junior Poster in Training

randindex cannot be declared as double because of two reasons :
1) You are using rand to generate a random number and store it in randindex. As rand() function only generates integers as random numbers randindex cant be double.
2) This is a more probable reason.. In line 17 you are saying the following :

cboxvalue[j]=boxvalue[RandIndex];

As the array of boxvalue only has integer numbers, i.e boxvalue[1] exists but boxvalue[1.12] does not exist !

Try declaring randindex as int... Your program should work great then !

adityatandon 23 Junior Poster in Training

Yea, thats so that your output can be formatted as u asked

|1| |2| |3| |4| |5|
|6| |7| |8| |9| |10|
|11| |12| |13| |14| |15|
|16| |17| |18| |19| |20|
|21| |22| |23| |24| |25|

Thats the output u want! Am i right ?
I have added if(j%5==0)cout<<"\n";
This shows that as soon as j is divisible by 5, it goes to the next line
Basically for formatting of your output !

adityatandon 23 Junior Poster in Training

Its very clear what your problem is ! You are opening the file using object inline without describing any mode... You have used fstream inline.
If you would like to use the file to input data into the file use ofstream inline and if you would like to view data from the file use ifstream inline !!

adityatandon 23 Junior Poster in Training

I dont think u should ask him to use vectors as that is a concept after arrays and unless you cant master the simpler ones, vectors are gonna be tougher for him... In my opinion, the doubt is pretty basic which makes very clear that he needs more practice with the basics... If you can, read 'passing arrays to functions using pointers' as that would be enough at this level to solve your problem. Try simpler stuff and become confident in the basics, only then learn more complicated things.. Coz if u dont... ur gonna keep screwing up !!

WaltP commented: I completely agree about vectors. Too many people believe vectors are the greatest thing since the wheel. But arrays are taught first because they are more universal. +17
adityatandon 23 Junior Poster in Training

Ok... I've gone through ur program.. Few suggestions :
1) There are errors in your main program.
The three errors are :
a) You are using 'int main' and there is no return statement
b) While declaring the array 'array' you havent specified array size(left [] blank)
c) After int box[26], you've used a comma, use a semicolon

Tip : While accepting an array as a parameter in a function, it is always best to do it using a pointer.
Eg: void showbox(int *box) is better than void showbox(int box[])
Reason : Turbo C++ gives an error while using the second method and i think you are using Turbo C++ Ver 3.0. Also, the function is called as usual.
To call function : showbox(box) and not showbox(box[])

These are a few noticeable errors/suggestions.. try incorporating these and see if ur program works.. If not, i've already written the source code for the entire program and i'll give it to u, but only once u've tried and reached somewhere and yes, ofcourse if u need it anymore

adityatandon 23 Junior Poster in Training

hmm... regarding arranging the boxes, do the following :

int j=0;
for( int i=0; i<26; i++)
	{
		cout<<" "<<"|"<<box[i]<<"|";
	              ++j;
              if(j%5==)
                 cout<<"\n";
}

So that dealt with, regarding storing the numbers in the box, what u are doing is correct, except giving a declaration inside the for loop, which leads to memory leak.
The following code should correct ur problem :

int RandIndex;
for(int i=0; i<26; i++)
	{
	    RandIndex=rand() % 26;
		box[i]=amount_in_box[RandIndex];
		cout<<box[i]<<endl;
	}
adityatandon 23 Junior Poster in Training

Umm... not clear what u want to do... Do u want to print the corresponding amount u win when u pick a box ?
eg : if the random no randindex generates is 3, the amount shown is 5 . Is that what ur trying to do ?
Secondly, why r u using set width and set precision.. They dont show any difference here as they are meant to set the decimal point on a floating point number. In this case all ur numbers are whole numbers and there is no decimal.. hence no difference !

adityatandon 23 Junior Poster in Training

Yea pretty evident...
1) Using int main with no return statement
Thats ur problem i think
2) Y r u calling it 5 times ?? Calling it once will make it sort...

3)Next thing in ur bubble sort, there is no increment of pass in the for loop.. pass++ or ++ pass.

4)Lastly, ur loop is exited after the first entrance because of && flag==1
Try it after removing that

Dont mind me, but ur program is less of a program nd more of a problem :P