Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Nothingness

Over my head!

This topic is 6139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I HAVE to make a program that 1.Makes 100 random numbers 2.Make sure none of the random numbers equal the any other number 3.Ask a user for 3 numbers, between certain numbers 4.Make sure none of the asked numbers are the same as the randome numbers 5. Do 2 kinds of searches (linear, binary) 6. Get the time taken to get the numbers using either the linear or the binary searches. The problem is i dont no how to do linear, or binary searches. Nor do I know how to sort or use pointers that good. I have to do this by tuesday, for my ap computer science class, but for the past year instead of learning c++ i learned java, and now all of a sudden i have to do this. Here is the source i already have, but it has errors, and i still have to make a function to get the time, and a binary search function. I have like 10 errors, and i dont no how toget rid of them, Please HELP!!
  
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#define size 100;

void seq();
//void binary();



void sort(*array)
{

 int min, randnum[100];
 int x,i,j,front,back,middle,num1,num2,num3,ele;

//get three numbers to be found.

cout <<"Please enter a number between 1 - 33: ";
cin>>num1;
cout <<"\n\nPlease enter a number between 34-66: ";
cin>>num2;
cout <<"\n\nPleae enter a number between 67-100: ";
cin>>num3;

for(i=1; i<=size; i++)
   {
   //set 3 elements to numbers from the user    

   front = num1;
   middle = num2;
   back = num3;
   
   //set the numbers in the randnum[i] places

   randnum[rand() % i] = front;
   randnum[rand() % i] = middle;
   randum[rand() % i] = back;

   //get 100 random numbers (between 1 - 100) 

   srand((unsigned)time(NULL));
   randnum[i] = rand() % 100;
   
    //check if any number is the same

   if(randnum[i] = size - 1 || randnum[i] = front || randnum[i] = middle || randnum[i] = back)
     {
      do
       {
        //if any number is the same set the same elements to randomize again

        randnum[i] = ele;
        ele = rand() % 100;
       } while(randnum[i] = size - 1 || randnum[i] = front || randnum[i] = middle || randnum[i] = back)
    
     }
cout <<randnum[i] <<"\n\n";

//set the array to be the random array

array = randnum[i];

//sorting the numbers

for(i = 0; i<=size-1; i++)
{
  x = i;
  
  //gets the current values

  min = array[x];

//check if number is lower   

for(j = i+1; j<=size; j++)
   {
    if(array[j] <min)
    {
     x = j;
     min = array[x];  //if so then get that number

    }
   } 
}

  //switch values

   array[x] = array[i];  //should be just like randnum[i]

   array[a] = min;
seq(array[x],front, middle, back) 
}
}



void main()
{
  int *numbers;
  numbers = new int[100];
  sort(numbers);
  

//free the memory

delete [] numbers;

}
void seq(array[i],f,m,b)
{
 int, index[3], target[3];
bool found;
found = false;
 index=0;
 

target[0] = f;      //front

target[1] = m;      //middle

target[2] = b;      //back


//search for the targets

for(i =0; i<=size; i++)
{
 for(int j=0; j<=2; j++)
  {
   
	 do
	 {		 
    if(array[index[i]] == target[j])
     { 
	//found the numbers

        found = true;
        cout <<"\nFound number" <<target[j];
        cout <<"\n"<<index[i];
        cout <<"\nFound number" <<target[j];
        cout <<"\n"<<index[i];
        cout <<"\nFound number" <<target[j];
        cout <<"\n"<<index[i];
      }
    else
       index++;
   }while((index[i] <size) && !found))
    
 }    

}
}
  

Share this post


Link to post
Share on other sites
Advertisement
as this is the absolutely most obvious homework question i have ever seen here to date, the only advice i can give you is to read your textbook and/or class notes.

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!