Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 11-10-2001, 01:44 PM   #1
Member (6 bit)
 
chpco2000's Avatar
 
Join Date: Sep 2001
Location: Cali
Posts: 48
C++ program, Compiler isnt detecting any errors, but there is an error(s)

Hello everyone,

For my C++ programming class, I had to write the source file.
It's a program that generates 200 integers randomly and stores them in an array. Sorts those numbers in descending order, seaches the array for the number 65, and then finds the integer whih occurs the most frequently.

I'm using MicroSoft Visual C++ 6.0 and the compiler isnt detecting any errors, but when I build and run the program, I get an error message in windows stating something about an illegal operation.
Can anyone help?

Here's the code:

#include //cout
#include //srand

using namespace std;
void rnum(int *);
void sort(int [], int);
void swap(int *, int *);
void search(int [], int);
int frequency(int[], int);

int main()
{
const int size=200; //declarations
int i;
int ray[size]={0};

rnum(ray); //call rnum function
sort(ray, size); //call sort function
for(i=0; i<200; i++){
cout< cout< }
cout<<"Searching for number 65 \n"<< endl;
search(ray, size);

cout<<"The number that occurs the most frequently is "< <
return 0;

}
/***********************************End of Main Function********************************/
/***********************************Start Rnum Function*********************************/
void rnum(int *rptr)
{
int i, k=0;
rand();
for(i=1; i<=200; i++){
k=10 +rand()%(100-10+1); //generate random #
*rptr=k; //store number in array
*(rptr++);
}
}
/***********************************End Rnum Function***********************************/
/**********************************Start Sort Function**********************************/
void sort(int ray[], int size)
{
int pass, i;

for(pass=0; pass for(i=0; i if(ray[i] < ray[i+1])
swap(&ray[i], &ray[i+1]); //call swap function
}

}
/***********************************End Sort Function***********************************/
/**********************************Start Swap Function**********************************/
void swap(int *oneptr, int *twoptr)
{
int temp;
temp=*oneptr;
*oneptr=*twoptr; //swapping values
*twoptr=temp;
}
/***********************************End Swap Function***********************************/
/*********************************Start Search Function*********************************/
void search(int ray[], int size)
{
int low=0, high=size-1, middle;
while(low<=high){
middle=(low+high)/2; //divide array in half
if(ray[middle]==65)
cout<<"Success, the number 65 was found" < else{
if(65 high=middle-1; //search upper half
else
low=middle+1; //search lower half
if(low==high)
cout<<"The number 65 was not found"< } //end else
} //end while
}
/*********************************End Search Funtion************************************/
/******************************Start Frequency Function*********************************/
int frequency(int ray[], int size)
{
int num,i, k=0, c1=0, c2=0;
const int size2=90;
int freq[size2]={0}; //declaring array
for(num=0; num k=ray[num]; //comparison value
for(i=1; i if(ray[i]==ray[num])
c1++;
}
freq[c2]=c1; //assign to freq array
c2++;
}
sort(freq, size2);
return freq[0];
}

Edit: Opps...My logic is way off on finding the most frequently occuring number.

Last edited by chpco2000; 11-10-2001 at 01:46 PM.
chpco2000 is offline   Reply With Quote
Old 11-19-2001, 04:12 AM   #2
Member (7 bit)
 
kcbhiw's Avatar
 
Join Date: May 2000
Location: Atlanta, Georgia
Posts: 95
in the search routine, what's goin on with this line?

cout<<"Success, the number 65 was found" < else{


try..

cout<<"Success, the number 65 was found"; else{

AND....

instead of..

cout<<"The number 65 was not found"< } //end else

try..

cout<<"The number 65 was not found"; } //end else



i didn't analyze the code too hard, but this just stood out. drop a line if you're still having trouble.
hope this helps

Last edited by kcbhiw; 11-19-2001 at 04:19 AM.
kcbhiw is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:40 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2