please help me

0 john conrad visitacion · June 22, 2014
guys please help me i getting an error message with this code..
//array.cpp
//demonstrates arrays
#include
using namespace std; ////////////////////////////////////////////////////////////////
int main()
{
int arr[100];                //array
int nElems = 0;              //number of items
int j;                       //loop counter
int searchKey;               //key of item to search for
//--------------------------------------------------------------
arr[0] = 77;                 //insert 10 items
arr[1] = 99;
arr[2] = 44;
arr[3] = 55;
arr[4] = 22;
arr[5] = 88;
arr[6] = 11;
arr[7] = 00;
arr[8] = 66;
arr[9] = 33;
nElems = 10;                 //now 10 items in array
//--------------------------------------------------------------
//--------------------------------------------------------------
for(j=0; j<nElems; j++)      //display items
cout << arr[j] << â?? â??;
cout << endl;
//--------------------------------------------------------------
searchKey = 66;              //find item with key 66
for(j=0; j<nElems; j++)      //for each element,
if(arr[j] == searchKey)   //found item?
break;                 //yes, exit before end
if(j == nElems)              //at the end?
cout << â??Canâ??t find â?? << searchKey << endl; //yes
else
cout << â??Found â?? << searchKey << endl;      //no
//--------------------------------------------------------------
searchKey = 55;              //delete item with key 55
cout << â??Deleting â?? << searchKey << endl;
for(j=0; j<nElems; j++)      //look for it
if(arr[j] == searchKey)
break;
for(int k=j; k<nElems; k++)  //move higher ones down
arr[k] = arr[k+1];
nElems--;                    //decrement size
//--------------------------------------------------------------
for(j=0; j<nElems; j++)      //display items
cout << arr[j] << â?? â??;
cout << endl;
return 0; }  //end main()

Post a Reply

Replies

Oldest  Newest  Rating
+1 Çağlan Turgut · August 31, 2014
Maybe you can share your code


std::cout << "That Way" << std::endl;

so we can analyze it better :).  Also it's better if you share the error code. It may be caused by your setup. I hope you've found the solution..

Happy, coding..
0 ragmar thomas · September 1, 2014
#include<iostream>

using namespace std;

int main()
{
    int arr[100]; //array
    int nElems = 0; //number of items
    int j; //loop counter
    int searchKey; //key of item to search for

    arr[0] = 77; //insert 10 items
    arr[1] = 99;
    arr[2] = 44;
    arr[3] = 55;
    arr[4] = 22;
    arr[5] = 88;
    arr[6] = 11;
    arr[7] = 00;
    arr[8] = 66;
    arr[9] = 33;
    nElems = 10; //now 10 items in array

for(j=0; j<nElems; j++) //display items
    cout << arr[j] << " ";
    cout << endl;

searchKey = 66; //find item with key 66

for(j=0; j<nElems; j++) //for each element,
    if(arr[j] == searchKey) //found item?
    break; //yes, exit before end
    
if(j == nElems) //at the end?
    cout << "Can't find " << searchKey << endl; //yes
    
else
    cout << "Found " << searchKey << endl; //no

searchKey = 55; //delete item with key 55

cout << "Deleting" << searchKey << endl;

for(j=0; j<nElems; j++) //look for it
    if(arr[j] == searchKey)
    break;
    
for(int k=j; k<nElems; k++) //move higher ones down
    arr[k] = arr[k+1];
    nElems--; //decrement size

for(j=0; j<nElems; j++) //display items
    cout << arr[j] << " " ;
    cout << endl;
    
return 0;
} //end main()



instead of separating lines with commenting  it is better to space with constant space indentation it looks better, i have learned it from the bests.
And btw i have posted a code in linear and binary search if you are interested by the name "switch statement crashing the program" above your post,  it works well. enjoy
  • 1

C++

103,604 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator