0

This is my first thred here!

This code is for a glossary test from swedish to english.

I have problem with (*it).engelska)! And why cant i use (*it).engelska in this code?

Many Thanks in advance!!

void prov(list<Glosor> lista)
{
        string testet;
        int santal = 0;
        int rsvar = 0;
        list<Glosor>::iterator it;
        for(it = lista.begin(); it != lista.end(); it++){
            cout << (*it).svenska << " betyder på engelska: "; // *it writes the swedish word for translate.
            getline(cin, testet); //Here you write the english word and "if" function test if it's correct.
            if(testet == (*it).engelska){
                cout << "Ratt svar!\n";
                rsvar++;
                }
            else{
            cout << "Tyvärr fel svar rätt svar är: "<< (*it).engelska) << endl; // Here i use "it" to write the correct answare if you guess wrong. But it keep telling me "error: expected ';' before ')' token"
            }
            santal++;
        }
        cout << "Du hade " << rsvar << " rätt svar av " << santal << " möjliga" << endl;
}
Coding Mash
  • 3,338
  • 5
  • 24
  • 45
  • 1
    It would be helpful if you could spell out exactly why "cant i use (*it).engelska)". What error message are you getting? Even more helpful would be the definition of the "Glosor" class/struct. Perhaps the "engelska" field is marked "private"? If "prov" is a global function, then the "engelska" member needs to be made "public". – John Källén Sep 22 '12 at 10:32
  • @dasblinkenlight i think the problem is in the `(*it).engelska)`. isnt it ? – NullPoiиteя Sep 22 '12 at 10:36
  • 1
    @RegisteredUser Yes, I think OP copy/pasted the `if` line, but has forgotten to remove the closing parenthesis of his `if` statement. – Sergey Kalinichenko Sep 22 '12 at 10:42

1 Answers1

3

There is a closing parenthesis in line 15 after engelska that doesn't have a matching opening parenthesis:

cout << "Tyvärr fel svar rätt svar är: "<< (*it).engelska) << endl;
//                           here------------------------^

Also in the FOR loop @ line 7, use ++it instead of it++. The former doesn't create a copy of the iterator, meaning it performs faster.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143