An error in C++ code

Does anyone know what is wrong with this code?



#include
#include
using namespace std;

void main()
{
string words[100][2], answer, temp[2];
int i, j, span = 50;

words[0][0] = "amount";
words[0][1] = "the sum total";
words[1][0] = "anew";
words[1][1] = "in a new form or way";
words[2][0] = "apex";
words[2][1] = "the topmost point, climax";
words[3][0] = "apogee";
words[3][1] = "the farthest or highest point, climax";
words[4][0] = "append";
words[4][1] = "to attach, esp. as an appendix";
words[5][0] = "approbation";
words[5][1] = "approval";
words[6][0] = "ardor";
words[6][1] = "passion";
words[7][0] = "aria";
words[7][1] = "an air, melody, esp. in opera";
words[8][0] = "arid";
words[8][1] = "dry, barren";
words[9][0] = "arouse";
words[9][1] = "to excite, stir up";
words[10][0] = "artful";
words[10][1] = "tricky, crafty";
words[11][0] = "artisan";
words[11][1] = "a trained craftsman";
words[12][0] = "attic";
words[12][1] = "a room just under the roof of a house";
words[13][0] = "azure";
words[13][1] = "sky blue";
words[14][0] = "bachelor";
words[14][1] = "an umarried man";
words[15][0] = "balderdash";
words[15][1] = "nonsense, foolish talk";
words[16][0] = "balmy";
words[16][1] = "weak in the head, crazy";
words[17][0] = "barely";
words[17][1] = "only just, merely";
words[18][0] = "baseball";
words[18][1] = "the national game of the U.S.A.";
words[19][0] = "baseless";
words[19][1] = "groundless, without foundation";
words[20][0] = "basement";
words[20][1] = "the story of a building below the ground floor";
words[21][0] = "basso";
words[21][1] = "a bass voice";
words[22][0] = "bauble";
words[22][1] = "a bright, showy trinket of no value";
words[23][0] = "bawd";
words[23][1] = " a woman who keeps a brothel";
words[24][0] = "bawdy";
words[24][1] = "obscene, lewd";
words[25][0] = "bawl";
words[25][1] = "to shout";
words[26][0] = "bay";
words[26][1] = "a wide inlet of sea";
words[27][0] = "beige";
words[27][1] = "the color of natural wood";
words[28][0] = "belated";
words[28][1] = "late";
words[29][0] = "beleaguer";
words[29][1] = "to besiege";
words[30][0] = "belfry";
words[30][1] = "a bell tower";
words[31][0] = "bellboy";
words[31][1] = "a hotel or club page boy";
words[32][0] = "beloved";
words[32][1] = "much loved, favored";
words[33][0] = "bemire";
words[33][1] = "to cover with mud";
words[34][0] = "bemused";
words[34][1] = "dazed";
words[35][0] = "benevolence";
words[35][1] = "kindheartedness";
words[36][0] = "benevolent";
words[36][1] = "charitable";
words[37][0] = "benign";
words[37][1] = "kind, well-disposed";
words[38][0] = "benignant";
words[38][1] = "kind, gracious";
words[39][0] = "benignity";
words[39][1] = "kindliness";
words[40][0] = "bequest";
words[40][1] = "something that is left under a will";
words[41][0] = "berate";
words[41][1] = "to scold, chide";
words[42][0] = "bereave";
words[42][1] = "to deprive";
words[43][0] = "berserk";
words[43][1] = "frenzied";
words[44][0] = "beset";
words[44][1] = "to surround, hem in";
words[45][0] = "beside";
words[45][1] = "by the side of, close to";
words[46][0] = "besides";
words[46][1] = "moreover";
words[47][0] = "besiege";
words[47][1] = "to assail";
words[48][0] = "besmirch";
words[48][1] = "to cast a slur on, sully";
words[49][0] = "bespeak";
words[49][1] = "to indicate, show evidence of";
words[50][0] = "bestial";
words[50][1] = "of or like a beast";
words[51][0] = "bestow";
words[51][1] = "to confer";
words[52][0] = "beta";
words[52][1] = "the second letter of the Greek alphabet";
words[53][0] = "better";
words[53][1] = "to improve";
words[54][0] = "betterment";
words[54][1] = "improvement";
words[55][0] = "bettor";
words[55][1] = "a person who bets";
words[56][0] = "beverage";
words[56][1] = "a drink";
words[57][0] = "bevy";
words[57][1] = "a group or company";
words[58][0] = "beware";
words[58][1] = "to be careful";
words[59][0] = "bicker";
words[59][1] = "to squabble";
words[60][0] = "bide";
words[60][1] = "to wait for the right opportunity";
words[61][0] = "bike";
words[61][1] = "a bicycle";
words[62][0] = "bile";
words[62][1] = "ill humour";
words[63][0] = "bilious";
words[63][1] = "sickly looking";
words[64][0] = "bilk";
words[64][1] = "to evade";
words[65][0] = "bill";
words[65][1] = "a beak";
words[66][0] = "billfold";
words[66][1] = "a wallet for holding paper money";
words[67][0] = "binary";
words[67][1] = "consisting of two";
words[68][0] = "binge";
words[68][1] = "a drinking spree";
words[69][0] = "biped";
words[69][1] = "having two feet";
words[70][0] = "birth";
words[70][1] = "the event of being born";
words[71][0] = "birthmark";
words[71][1] = "a mark on the skin at birth";
words[72][0] = "bisect";
words[72][1] = "to cut into two equal parts";
words[73][0] = "bisque";
words[73][1] = "a rich soup from shellfish";
words[74][0] = "blame";
words[74][1] = "to hold responsible";
words[75][0] = "bland";
words[75][1] = "mild";
words[76][0] = "blandish";
words[76][1] = "to coax or flatter";
words[77][0] = "blatant";
words[77][1] = "strident, harsh";
words[78][0] = "blather";
words[78][1] = "to talk foolishly";
words[79][0] = "blaze";
words[79][1] = "a bright fire";
words[80][0] = "bleak";
words[80][1] = "cheerless";
words[81][0] = "blear";
words[81][1] = "to blur";
words[82][0] = "bleat";
words[82][1] = "to speak plaintively";
words[83][0] = "blemish";
words[83][1] = "to spoil or impair";
words[84][0] = "blend";
words[84][1] = "a harmonious mixture";
words[85][0] = "bless";
words[85][1] = "to enrich";
words[86][0] = "bliss";
words[86][1] = "great but quiet enjoyment";
words[87][0] = "blithe";
words[87][1] = "lightheartedly cheerful, happy";
words[88][0] = "blooper";
words[88][1] = "a blunder";
words[89][0] = "blues";
words[89][1] = "a type of jazz";
words[90][0] = "blur";
words[90][1] = "to become indistinct";
words[91][0] = "blurry";
words[91][1] = "indistinct";
words[92][0] = "blurt";
words[92][1] = "to say impulsively";
words[93][0] = "boar";
words[93][1] = "the uncastrated male pig";
words[94][0] = "boatswain";
words[94][1] = "a ship's officer who calls men on duty";
words[95][0] = "bodice";
words[95][1] = "the top of a woman's dress";
words[96][0] = "bogey";
words[96][1] = "one over par";
words[97][0] = "bogus";
words[97][1] = "sham";
words[98][0] = "boisterous";
words[98][1] = "gutsy";
words[99][0] = "bold";
words[99][1] = "brave";
words[100][0] = "box";
words[100][1] = "a cuff or slap";

cout << "Press enter to sort the words...";
cin >> answer;

while(span)
{
for(i = span; i < 99; i++)
{
j = i - span + 1;
for(j = i - span + 1; j < 1; j - span)
{
if(words[j][0] <= words[j + span][0]) break;
temp[0] = words[j][0];
words[j][0] = words[j + span][0];
words[j + span][0] = temp[0];
temp[1] = words[j][1];
words[j][1] = words[j + span][1];
words[j + span][1] = temp[1];

}
}
span >>= 1;
}

cout << "Enter a word to be defined: ";
cin >> answer;

for(j = 0; j < 100; j++)
{
if(words[j][0] == answer)
{
cout << words[j][0] << endl;
cout << words[j][1] << "

";
}
}
}

Comments

  • : void main()
    main returns an int

    : words[100][0] = "box";
    : words[100][1] = "a cuff or slap";
    These are outside the bounds of your array (not good)
    Either remove this pair, or go for
    string words[101][2]

    : temp[0] = words[j][0];
    : words[j][0] = words[j + span][0];
    : words[j + span][0] = temp[0];
    : temp[1] = words[j][1];
    : words[j][1] = words[j + span][1];
    : words[j + span][1] = temp[1];
    A small point, but there is no need for temp[0] and temp[1]
    A simple temp will suffice


  • Don't worry. I've fixed the problem.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories