ok so basically my code is complete but I keep getting an error on one of my brackets and it says I need to put a ' ; ' behind "int LinearSearchArray ( const int list[], int numEless, int value)" and when I do that it brings up more errors. Besides the bracket error my code is complete. The error is at the bottom of my code and I made a comment with a arrow pointing to the error. Thanks

#include <string>
#include <iostream>
#include <ctime>
#include <cmath>
#include <fstream>

using namespace std;

int main()
{
 
int linearSearchArray(const int[], int, int);


 
int vals[100];
fstream file;



 
string line =   "----------------------------------------------------\n";
       string msg2 =   " Please select an option from the above menu --> ";
       string menu1 =  " [0]    Quit \n"
         " [1]    Generate Rand Array \n"
         " [2]    Save Array to File \n"
         " [3]    Load Array from File \n"
         " [4]    Search Array \n"
         " [5]    Compute CPU Time \n";

int sz;
int max_range= 100;
int min_range= 0;
ofstream fout;
ifstream fin;
int idx;
int val;
long t0, t1;
int op = -1;
 
while( op != 0)
{
cout << menu1;
cout << msg2 << endl;
cin >> op;
cout << line << endl;
 
 
switch( op )
{

case 0: exit(0); break;

case 1:
int sz;
cout << " Please enter size of the array (sz <= 100) --> ";
cin >> sz;

if(sz > 1000){ //MAX_SZ
cout << " The size you entered is not allowed ...\n";
exit(0);
}
else{
int max_range = 100;
int min_range = 0;
for( int i=0; i<sz; ++i){
vals[i] = min_range +  rand() % max_range;
 
}
}
break;

case 2: 

 
float n1, n2;
 
  fout.open("fout.txt");

  for( int i=0; i<sz; ++i)
  {
 fout << vals[i] << endl;
  }

  fout.close();
  break;
 
  

  
 
case 3:
fin.open("fout.txt");
idx = 0;
while(fin){
fin >> vals[idx];
++idx;
}

sz = idx;
fin.close();
break;
case 4:
cout << " Please enter the value you are looking for --->";
cin >> val;
idx = linearSearchArray(vals, sz, val);
if( idx > -1)
cout << " The val (" << val << ") was found at index (" << idx << ") \n\n";
else 
cout << " The Val (" << val << ") was not found \n\n" ;

cout << "CPU time was" << t1-t0 << "ms\n\n"; 
 
 
case 5:
long t0 = clock(); //CPU Time
 
for(float i=0; i<100000; ++i)  
pow(i,i) * sqrt(i*i) / exp(i);
 
long t1 = clock();
 
cout << "running time in ms = " << t1-t0 << "\n";

case 6:
for(int i=0; i<sz; ++i)
{
cout <<  vals[i] << endl;
}
break;

default: cout << "Invalid option...Please try again \n\n";
}
return 0;
}
 
int LinearSearchArray ( const int list[], int numEless, int value)
 
{                         //<<--------this is where I get my error 
int index=0;
int position= -1;
bool found = false;


while(index < numEless &&!found)
{
found = true;
position = index;
}

index ++
}
return position
}

Recommended Answers

All 4 Replies

1) USE CODE TAGS!
2) Format your code.
Almost all errors like this can be avoided by proper formatting.
3) Never tell us what the error says, post it verbatim (copy/paste)

int LinearSearchArray ( const int list[], int numEless, int value)

{ //<<--------this is where I get my error
int index=0;
int position= -1;
bool found = false;


while(index < numEless &&!found)
{
found = true;
position = index;
}

index ++
}
return position
}

There is no semicolon after last two lines
index++ and return position

commented: Well Spotted +3

ok so basically my code is complete but I keep getting an error on one of my brackets and it says I need to put a ' ; ' behind "int LinearSearchArray ( const int list[], int numEless, int value)" and when I do that it brings up more errors. Besides the bracket error my code is complete. The error is at the bottom of my code and I made a comment with a arrow pointing to the error. Thanks

#include <string>
#include <iostream>
#include <ctime>
#include <cmath>
#include <fstream>

using namespace std;

int main()
{
 
int linearSearchArray(const int[], int, int);


 
int vals[100];
fstream file;



 
string line =   "----------------------------------------------------\n";
       string msg2 =   " Please select an option from the above menu --> ";
       string menu1 =  " [0]    Quit \n"
         " [1]    Generate Rand Array \n"
         " [2]    Save Array to File \n"
         " [3]    Load Array from File \n"
         " [4]    Search Array \n"
         " [5]    Compute CPU Time \n";

int sz;
int max_range= 100;
int min_range= 0;
ofstream fout;
ifstream fin;
int idx;
int val;
long t0, t1;
int op = -1;
 
while( op != 0)
{
cout << menu1;
cout << msg2 << endl;
cin >> op;
cout << line << endl;
 
 
switch( op )
{

case 0: exit(0); break;

case 1:
int sz;
cout << " Please enter size of the array (sz <= 100) --> ";
cin >> sz;

if(sz > 1000){ //MAX_SZ
cout << " The size you entered is not allowed ...\n";
exit(0);
}
else{
int max_range = 100;
int min_range = 0;
for( int i=0; i<sz; ++i){
vals[i] = min_range +  rand() % max_range;
 
}
}
break;

case 2: 

 
float n1, n2;
 
  fout.open("fout.txt");

  for( int i=0; i<sz; ++i)
  {
 fout << vals[i] << endl;
  }

  fout.close();
  break;
 
  

  
 
case 3:
fin.open("fout.txt");
idx = 0;
while(fin){
fin >> vals[idx];
++idx;
}

sz = idx;
fin.close();
break;
case 4:
cout << " Please enter the value you are looking for --->";
cin >> val;
idx = linearSearchArray(vals, sz, val);
if( idx > -1)
cout << " The val (" << val << ") was found at index (" << idx << ") \n\n";
else 
cout << " The Val (" << val << ") was not found \n\n" ;

cout << "CPU time was" << t1-t0 << "ms\n\n"; 
 
 
case 5:
long t0 = clock(); //CPU Time
 
for(float i=0; i<100000; ++i)  
pow(i,i) * sqrt(i*i) / exp(i);
 
long t1 = clock();
 
cout << "running time in ms = " << t1-t0 << "\n";

case 6:
for(int i=0; i<sz; ++i)
{
cout <<  vals[i] << endl;
}
break;

default: cout << "Invalid option...Please try again \n\n";
}
return 0;
}
 
int LinearSearchArray ( const int list[], int numEless, int value)
 
{                         //<<--------this is where I get my error 
int index=0;
int position= -1;
bool found = false;


while(index < numEless &&!found)
{
found = true;
position = index;
}

index ++
}
return position
}

Your "LinearSearchArray" function is defined within main() - it needs to be defined globally. Also, you have 5 brackets in this function, so you either have to add one more or remove one. Having an odd number of brackets is never a good thing!

ok so basically my code is complete but I keep getting an error on one of my brackets and it says I need to put a ' ; ' behind "int LinearSearchArray ( const int list[], int numEless, int value)" and when I do that it brings up more errors. Besides the bracket error my code is complete. The error is at the bottom of my code and I made a comment with a arrow pointing to the error. Thanks

#include <string>
#include <iostream>
#include <ctime>
#include <cmath>
#include <fstream>

using namespace std;

int main()
{
 
int linearSearchArray(const int[], int, int);


 
int vals[100];
fstream file;



 
string line =   "----------------------------------------------------\n";
       string msg2 =   " Please select an option from the above menu --> ";
       string menu1 =  " [0]    Quit \n"
         " [1]    Generate Rand Array \n"
         " [2]    Save Array to File \n"
         " [3]    Load Array from File \n"
         " [4]    Search Array \n"
         " [5]    Compute CPU Time \n";

int sz;
int max_range= 100;
int min_range= 0;
ofstream fout;
ifstream fin;
int idx;
int val;
long t0, t1;
int op = -1;
 
while( op != 0)
{
cout << menu1;
cout << msg2 << endl;
cin >> op;
cout << line << endl;
 
 
switch( op )
{

case 0: exit(0); break;

case 1:
int sz;
cout << " Please enter size of the array (sz <= 100) --> ";
cin >> sz;

if(sz > 1000){ //MAX_SZ
cout << " The size you entered is not allowed ...\n";
exit(0);
}
else{
int max_range = 100;
int min_range = 0;
for( int i=0; i<sz; ++i){
vals[i] = min_range +  rand() % max_range;
 
}
}
break;

case 2: 

 
float n1, n2;
 
  fout.open("fout.txt");

  for( int i=0; i<sz; ++i)
  {
 fout << vals[i] << endl;
  }

  fout.close();
  break;
 
  

  
 
case 3:
fin.open("fout.txt");
idx = 0;
while(fin){
fin >> vals[idx];
++idx;
}

sz = idx;
fin.close();
break;
case 4:
cout << " Please enter the value you are looking for --->";
cin >> val;
idx = linearSearchArray(vals, sz, val);
if( idx > -1)
cout << " The val (" << val << ") was found at index (" << idx << ") \n\n";
else 
cout << " The Val (" << val << ") was not found \n\n" ;

cout << "CPU time was" << t1-t0 << "ms\n\n"; 
 
 
case 5:
long t0 = clock(); //CPU Time
 
for(float i=0; i<100000; ++i)  
pow(i,i) * sqrt(i*i) / exp(i);
 
long t1 = clock();
 
cout << "running time in ms = " << t1-t0 << "\n";

case 6:
for(int i=0; i<sz; ++i)
{
cout <<  vals[i] << endl;
}
break;

default: cout << "Invalid option...Please try again \n\n";
}
return 0;
}
 
int LinearSearchArray ( const int list[], int numEless, int value)
 
{                         //<<--------this is where I get my error 
int index=0;
int position= -1;
bool found = false;


while(index < numEless &&!found)
{
found = true;
position = index;
}

index ++
}
return position
}

Ooops - sorry, your function is not defined within main(). However, you do have 13 brackets in main(), so again, you need to add one more or remove one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.