C ++ Game Started terminated called after launching an instance of 'std :: out_of_range'

advertisements

Error is at the bottom with the output.

 Output:

Welcome to my Scramble Word Game!

a) Add Words into game database b) Remove words c) configure count down time d) Start game e) Select Game level f) View score chart g) Quit Please enter an alphabet to select: d

Game Started terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check apple orange melon lemondinosaur RUN FINISHED; Aborted; real time: 1s; user: 0ms; system: 0ms

below the code is my output , whats wrong with my code can anyone help me thanks , Any help will be appreciated! Cheers!


levelList.at(rand()% wordList.size());

This is likely to be out of range some of the time, since wordList is likely to be larger than levelList.

Presumably, you meant

levelList.at(rand()% levelList.size());
                     ^^^^^^^^^

You are also not initialising the level variable declared in startGame, so it's likely that levelList will be completely empty. Presumably, you want to use the function argument to specify the level instead.