mardi 16 novembre 2021

Program is compiling on repl but not on g++

I have the makefile working correctly, It will not compile on my g++ compiler that we need to compile it with for grading in our class. I am not sure what to do about the errors because I believe my brackets are all correct.

My main where all the errors are:

#include <iostream>
#include <list>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string.h>
using namespace std;
#include "HashTable.h"
#include "HashTableToo.h"
#include "TimeInterval.h"
#define MIN(x,y) ((x) < (y) ? (x) : (y)) //calculate minimum between two values
int hashGetterFirst(string value){
    int hashValue =0;
    char letter;
    letter = value[0];// second letter 
    if(letter=='a'){
        hashValue = 0;
    }
    if(letter=='b'){
        hashValue = 1;
    }
    if(letter=='c') hashValue = 2;
    if(letter=='d') hashValue = 3;
    if(letter=='e') hashValue = 4;
    if(letter=='f') hashValue = 5;
    if(letter=='g') hashValue = 6;
    if(letter=='h') hashValue = 7;
    if(letter=='i') hashValue = 8;
    if(letter=='j') hashValue = 9;
    if(letter=='k') hashValue = 10;
    if(letter=='l') hashValue = 11;
    if(letter=='m') hashValue = 12;
    if(letter=='n') hashValue = 13;
    if(letter=='o') hashValue = 14;
    if(letter=='p') hashValue = 15;
    if(letter=='q') hashValue = 16;
    if(letter=='r') hashValue = 17;
    if(letter=='s') hashValue = 18;
    if(letter=='t') hashValue = 19;
    if(letter=='u') hashValue = 20;
    if(letter=='v') hashValue = 21;
    if(letter=='w') hashValue = 22;
    if(letter=='x') hashValue = 23;
    if(letter=='y') hashValue = 24;
    if(letter=='z') hashValue = 25;
    return hashValue;
}

int hashGetterSecond(string value){
    int hashValue =0;
    char letter;
    letter = value[1];// second letter 
    if(letter=='a'){
        hashValue = 0;
    }
    if(letter=='b'){
        hashValue = 1;
    }
    if(letter=='c') hashValue = 2;
    if(letter=='d') hashValue = 3;
    if(letter=='e') hashValue = 4;
    if(letter=='f') hashValue = 5;
    if(letter=='g') hashValue = 6;
    if(letter=='h') hashValue = 7;
    if(letter=='i') hashValue = 8;
    if(letter=='j') hashValue = 9;
    if(letter=='k') hashValue = 10;
    if(letter=='l') hashValue = 11;
    if(letter=='m') hashValue = 12;
    if(letter=='n') hashValue = 13;
    if(letter=='o') hashValue = 14;
    if(letter=='p') hashValue = 15;
    if(letter=='q') hashValue = 16;
    if(letter=='r') hashValue = 17;
    if(letter=='s') hashValue = 18;
    if(letter=='t') hashValue = 19;
    if(letter=='u') hashValue = 20;
    if(letter=='v') hashValue = 21;
    if(letter=='w') hashValue = 22;
    if(letter=='x') hashValue = 23;
    if(letter=='y') hashValue = 24;
    if(letter=='z') hashValue = 25;
    return hashValue;
}



int main() {
    string itrWord ;
    int min = 99;
    string minWord;
    int i,j,len1,len2,checker,tracker;
    int distance[50][50];
    vector<string> arry;
    vector<string> testArry;
    //make the count
    TimeInterval timer;
    // start the count
    timer.start();
    // create two hash table objects 
    HashTable Ht; // first letter hash function
    HashTableToo HtT; // second letter hash function

    // read in the words and add all of them to both hash tables.
    ifstream file("Dictionary.txt");
    string word;
    /* add the words from the dictonary to the 2 hash tables. one hash table is based on the strings first letter and the other is based on the strings second letter. */
  while(file >> word){
        string temp = word;
        transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
        Ht.insert(temp);
        HtT.insert(temp);
  }
    /* getting the word to be tested, setting to lowercase and getting the key that it would be in for each HashTable if it exists in the dictonary */
    cout<<"please enter a word to be tested by the dictionary(lowercase only)"<<endl;
    string tested;
    cin>>tested;
    // make it lowercase just in case the user did not follow instructions 
    transform(tested.begin(), tested.end(), tested.begin(), ::tolower);
    // get the two keys for the hash tables that this word resides in
    int keyOne = hashGetterFirst(tested);
    int keyTwo = hashGetterSecond(tested);
    bool found = false;
    /*if case1: if the word exists, respond with true and list all of the words with the same first 2 letters.*/
    if(Ht.searchTable(tested)!=""){
        found = true;
        cout<<"True"<<endl;
        cout<<"Words in the dictonary that have the same first two letters as your word: "<<tested<<endl;
        // create an array of the keys in hash table one at the key the word is at.
        arry = Ht.keytoArray(keyOne);
        /*go through the array and check to see which ones are in the same second has table as the searched word.*/
        for (auto i: arry){
        if(HtT.searchTableKey(keyTwo,i)==""){   

            }else if(HtT.searchTableKey(keyTwo,i)!=tested){
                cout<<i<<endl;
            }
        }
    } // end case 1  

    /* else case2: if it does not exist, ask if a suggested word if the spelling is close, if they put "n" then return false if they put "y" return true and print words with the same first two letters.*/
    // assume first letter is correct

    /* used Levinstein/Edit Distance to determine which word was the closest to the word if it was misspelled */
    
    else{
    arry = Ht.keytoArray(keyOne);
    for(auto x: arry){
    itrWord = x;
    len1 = tested.length();
    len2= itrWord.length();
   for(i=0;i<=len1;i++) {
      distance[0][i] = i;
   }
   for(j=0;j<=len2;j++) {
      distance[j][0] = j;
   }
   for (j=1;j<=len1;j++) {
      for(i=1;i<=len2;i++) {
         if(tested[i-1] == itrWord[j-1]) {
            tracker= 0;
         } else {
            tracker = 1;
         }
         checker = MIN((distance[i-1][j]+1),(distance[i][j-1]+1));
         distance[i][j] = MIN(checker,(distance[i-1][j-1]+tracker));
      }
   }
   if(distance[len2][len1]<min){
       min = distance[len2][len1];
       minWord = itrWord;
   }
}
}
bool ccheck = false;
// case3 if the word is too far off then just return false.
if(min>=6){
    cout<<"False"<<endl;
 ccheck = true;
}

if(ccheck==false){
cout << "did you mean "<<minWord<<" The Levinstein distance is: "<<min <<" respond with a lowercase y if this is your word or a lowecase n if it is not your word"<<endl;
char response;
cin>>response;
if(response=='y'){

int minKeyOne = hashGetterFirst(minWord);
int minKeyTwo =hashGetterSecond(minWord);
cout<<"True"<<endl;
        cout<<"Words in the dictonary that have the same first two letters as your word: "<<minWord<<endl;
        // create an array of the keys in hash table one at the key the word is at.
        testArry = Ht.keytoArray(minKeyOne);

        /* will go through the array and check to see which ones are in the same second has table as the searched word.*/
        for (auto i: testArry){
        if(HtT.searchTableKey(minKeyTwo,i)==""){    

            }else if(HtT.searchTableKey(minKeyTwo,i)!=minWord){
                cout<<i<<endl;
            }
        }
}
else{
    cout<<"False"<<endl;
}
}
// stop the count and display the results
    timer.stop(); cout<<"time interval: "<<round(timer.GetInterval())<<" microseconds"<<endl;
    return 0;
}

Errors: I am not sure what to do about the autotype variable, and I do not understand why it is expecting ;,), and } before the end of the loop.

main.cpp:135:13: error: 'i' does not name a type
   for (auto i: arry){
             ^
main.cpp:142:2: error: expected ';' before '}' token
  } // end case 1
  ^
main.cpp:142:2: error: expected primary-expression before '}' token
main.cpp:142:2: error: expected ';' before '}' token
main.cpp:142:2: error: expected primary-expression before '}' token
main.cpp:142:2: error: expected ')' before '}' token
main.cpp:142:2: error: expected primary-expression before '}' token
main.cpp:142:2: error: expected ';' before '}' token
main.cpp:151:11: error: 'x' does not name a type
  for(auto x: arry){
           ^
main.cpp:177:1: error: expected ';' before '}' token
 }
 ^
main.cpp:177:1: error: expected primary-expression before '}' token
main.cpp:177:1: error: expected ';' before '}' token
main.cpp:177:1: error: expected primary-expression before '}' token
main.cpp:177:1: error: expected ')' before '}' token
main.cpp:177:1: error: expected primary-expression before '}' token
main.cpp:177:1: error: expected ';' before '}' token
main.cpp:199:13: error: 'i' does not name a type
   for (auto i: testArry){
             ^
main.cpp:206:1: error: expected ';' before '}' token
 }
 ^
main.cpp:206:1: error: expected primary-expression before '}' token
main.cpp:206:1: error: expected ';' before '}' token
main.cpp:206:1: error: expected primary-expression before '}' token
main.cpp:206:1: error: expected ')' before '}' token
main.cpp:206:1: error: expected primary-expression before '}' token
main.cpp:206:1: error: expected ';' before '}' token

Thank you in advance for your time

Aucun commentaire:

Enregistrer un commentaire