localSettings cast exception - casting

I try to check if the Setting "tournament" is already set and if not then set the default to 4.
But when I run this it crashes with an exception: Platform::InvalidCastException ^
Where is the invalid cast?
ApplicationDataCompositeValue^ tournament_composite = safe_cast<ApplicationDataCompositeValue^>(localSettings->Values->Lookup("tournament"));
if (tournament_composite == nullptr)
{
values->Insert("tournament", dynamic_cast<PropertyValue^>(PropertyValue::CreateInt32(4)));
}
else
{
int tournament = safe_cast<IPropertyValue^>(tournament_composite->Lookup("tournament"))->GetInt32();
switch (tournament)
{
case 0:
lb_tournament->SelectedIndex = 4;
break;
case 3:
lb_tournament->SelectedIndex = 0;
break;
case 5:
lb_tournament->SelectedIndex = 1;
break;
case 7:
lb_tournament->SelectedIndex = 2;
break;
case 11:
lb_tournament->SelectedIndex = 3;
break;
default:
lb_tournament->SelectedIndex = 4;
break;
}
}

Related

Switch Statement Only Defaults c++

So I'm writing some code and I have this switch statement to set some bools in a 2d array. I have a nested for loop and a switch with switches in the nested loop setting on outer loop int i and inner loop int e. grammar[i][e] I'm switching on i and then on e but for some reason it just defaults on me. I have it printing out i and e.. and it still just defaults so there must be something wrong with my switch statements but I'm not seeing the issue here.
bool follows = false;
for (int i = 0; i < 12; i++)
{
// 1 noun, 2 pronoun, 3 verb, 4 adverb, 5 adjective, 6 preposition, 7 conjunction, 8 determiner, 9 interjection, 10 exclamation, 11 notype, 12 auxiliary
for (int e = 0; e < 12; e++)
{
//std::cout << " This is where we're at in grammar array " + std::to_string(i) + " and " + std::to_string(e);
switch (i)
{
case 0: // noun // noun
switch (e) {
case 0: // noun
follows = false;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = true;
break;
case 4: // adjective
follows = true;
break;
case 5: // preposition
follows = false;
break;
case 6: // conjunction
follows = true;
break;
case 7: // determiner
follows = true;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 1: // pronoun //pronoun
switch (e) {
case 0: // noun
follows = false;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = true;
break;
case 5: // preposition
follows = true;
break;
case 6: // conjunction
follows = true;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 2: // verb // verb
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = true;
break;
case 2: // verb
follows = false;
break;
case 3: // adverb
follows = true;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = false;
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 3: // adverb //adverb
switch (e) {
case 0: // noun
follows = false;
break;
case 1: // pronoun
follows = true;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = true;
break;
case 5: // preposition
follows = false;
break;
case 6: // conjunction
follows = true;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 4: // adjective //adjective
switch (e) {
case 0: // noun
follows = false;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = false;
break;
case 6: // conjunction
follows = true;
break;
case 7: // determiner
follows = true;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 5: // preposition //preposition
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = false;
break;
case 6: // conjunction
follows = true;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 6: // conjunction //conjunction
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = true;
break;
case 4: // adjective
follows = true;
break;
case 5: // preposition
follows = true; // change
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false; // change
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 7: // determiner //determiner
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = true;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = true;
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 8: // interjection //interjection
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = false;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = true;
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 9: // exclamation //exclamation
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = false;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = true;
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 10: //NoType //NoType
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = false;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = true;
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = true;
break;
default:
break;
}
case 11: //auxiliary
switch (e) {
case 0: // noun
follows = true;
break;
case 1: // pronoun
follows = false;
break;
case 2: // verb
follows = false;
break;
case 3: // adverb
follows = false;
break;
case 4: // adjective
follows = false;
break;
case 5: // preposition
follows = true;
break;
case 6: // conjunction
follows = false;
break;
case 7: // determiner
follows = false;
break;
case 8: // interjection
follows = true;
break;
case 9: // exclamation
follows = true;
break;
case 10: //NoType
follows = true;
break;
case 11: // auxiliary
follows = false;
break;
default:
break;
}
default:
// TODO CHANGE THIS
std::cout << "Defaulting for some reason." + std::to_string(i) + " on i ";
follows = true;
break;
}
grammar[i][e] = follows;
if (grammar[i][e]) { std::cout << std::to_string(i) + std::to_string(e) + " True "; }
else { std::cout << std::to_string(i) + std::to_string(e) + " False "; }
}
}
You should put breaks after all bigger switch statements.
break;
default:
break;
}
break; // <--- here
case 1: // pronoun //pronoun
switch (e) {

Numbers to words converter C++ coding

I'd to write a c++ project for my school that read and converts numbers in D:\Data\Input.txt to words and write them at bottom of Input.txt
I'd wrote the following code but it doesn't run good, its output for numbers below 15 isn't correct for example it converts 5 to two or 6 to twelve, etc.
I don't know how to solve its problems.
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<fstream>
using namespace std;
int q=0;
char ch[100][100];
char out[5000];
void first_digit(int yeki)
{
if (yeki<20)
switch (yeki)
{
case 1:
strcpy(ch[q],"one");
break;
case 2:
strcpy(ch[q],"two");
break;
case 3:
strcpy(ch[q],"three");
break;
case 4:
strcpy(ch[q],"four");
break;
case 5:
strcpy(ch[q],"five");
break;
case 6:
strcpy(ch[q],"six");
break;
case 7:
strcpy(ch[q],"seven");
break;
case 8:
strcpy(ch[q],"eight");
break;
case 9:
strcpy(ch[q],"nine");
break;
case 10:
strcpy(ch[q],"ten");
break;
case 11:
strcpy(ch[q],"eleven");
break;
case 12:
strcpy(ch[q],"twelve");
break;
case 13:
strcpy(ch[q],"thirteen");
break;
case 14:
strcpy(ch[q],"fourteen");
break;
case 15:
strcpy(ch[q],"fifteen");
break;
case 16:
strcpy(ch[q],"sixteen");
break;
case 17:
strcpy(ch[q],"seventeen");
break;
case 18:
strcpy(ch[q],"eighteen");
break;
case 19:
strcpy(ch[q],"nineteen");
break;
}
q++;
}
void second_digit(int dahi)
{
int a,b;
a=(dahi/10)%10;
b=dahi%10;
first_digit(b);
if (b!=0)
{
strcpy(ch[q]," - ");
q++;
}
switch (a)
{
case 2:
strcpy(ch[q],"twenty");
break;
case 3:
strcpy(ch[q],"thirty");
break;
case 4:
strcpy(ch[q],"forty");
break;
case 5:
strcpy(ch[q],"fifty");
break;
case 6:
strcpy(ch[q],"sixty");
break;
case 7:
strcpy(ch[q],"seventy");
break;
case 8:
strcpy(ch[q],"eighty");
break;
case 9:
strcpy(ch[q],"ninety");
break;
}
q++;
}
void third_digit(int sadi)
{
int a,b;
a=sadi/100;
b=sadi-(a*100);
if(b<20)
first_digit(b);
if(b>19)
second_digit(b);
if(b!=0)
{
strcpy(ch[q]," and ");
q++;
}
switch(a){
case 1:
strcpy(ch[q],"one hundred");
break;
case 2:
strcpy(ch[q],"two hundred");
break;
case 3:
strcpy(ch[q],"three hundred");
break;
case 4:
strcpy(ch[q],"four hundred");
break;
case 5:
strcpy(ch[q],"five hundred");
break;
case 6:
strcpy(ch[q],"six hundred");
break;
case 7:
strcpy(ch[q],"seven hundred");
break;
case 8:
strcpy(ch[q],"eight hundred");
break;
case 9:
strcpy(ch[q],"nine hundred");
break;
}
q++;
}
string numberProcess(string number)
{
char s[20],s1[number.length()+1];
strcpy(s1, number.c_str());
int i,j,k=8,n,p=0,l=1,sefr=0, x[9];
int va2,va;
j=number.length()+1;
strcpy(s,s1);
for (i=1 ;i<=8;i++)
x[i]=0;
for (i=j-1;i>=0;i--)
{
n=s[i]-48;
if (l==1000)
{
l=1;
k--;
}
x[k]=x[k]+(n*l);
l=l*10;
}
for (i=1;i<=8;i++)
sefr=sefr+x[i];
if(sefr==0)
{
strcpy(ch[q],"zero");
q++;
}
else
{
for (i=8;i>=1;i--)
if (x[i]!=0)
{
va2=0;
for (va=8;va>=i+1;va--)
va2=va2+x[va];
if(va2 != 0)
{
strcpy(ch[q]," and ");
q++;
}
switch(i)
{
case 7:
strcpy(ch[q]," Thousand ");
break;
case 6:
strcpy(ch[q]," Million ");
break;
case 5:
strcpy(ch[q]," billion ");
break;
case 4:
strcpy(ch[q]," Trillions ");
break;
case 3:
strcpy(ch[q]," Quadrillion ");
break;
case 2:
strcpy(ch[q]," Quintilion ");
break;
}
q++;
if (x[i]<20)
first_digit(x[i]);
if ((x[i]>19)&&(x[i]<100))
second_digit(x[i]);
if (x[i]>99)
third_digit(x[i]);
}
return out;
}
for(int df = 100; df>=0;df--)
{
if(strcmp(ch[df],"" ))
strcat(out ,ch[df]);
}
}
int main(){
ifstream datas;
string line;
datas.open("da.txt",ios::out);
if(datas)
{
while(getline(datas,line))
{
cout<<numberProcess(line);
}
}
return 0;
}

Why spi.recieve() function always return zero in SPI of mbed?

I want to set up a SPI connection between two mbed boards and I found that the spi.recieve() function which is used to detect the data transmission from the master always return zero and the connection can't be established.
I try to remove 'if' in my code, and it works, but I still don't understand why the function returns zero.
here is some code:
while (1)
{
transmit_value = 100 * voltage;
spislave.reply(transmit_value);
if (spislave.receive())
{
receive_value = spislave.read();
}
here is my completed code:
#include <mbed.h>
Serial pc(USBTX, USBRX);
SPISlave spislave(p5, p6, p7, p8);
AnalogIn voltage(p20);
PwmOut led(p21);
BusOut display(p9, p10, p11, p12, p13, p14, p15, p16);
DigitalOut GroundLeft(p27);
DigitalOut GroundRight(p28);
int main()
{
char transmit_value = 50;
char receive_value = 60;
spislave.format(8,0);
spislave.frequency(1000000);
while (1)
{
transmit_value = 100 * voltage;
spislave.reply(transmit_value);
if (!spislave.receive())
{
receive_value = spislave.read();
}
led.write(receive_value / 100.0);
int leftnum = receive_value / 10;
int rightnum = receive_value % 10;
pc.printf("%d\n", receive_value);
GroundLeft = 0;
GroundRight = 1;
switch (leftnum)
{
case 0:
display = 0x3F;
break;
case 1:
display = 0x06;
break;
case 2:
display = 0x5B;
break;
case 3:
display = 0x4F;
break;
case 4:
display = 0x66;
break;
case 5:
display = 0x6D;
break;
case 6:
display = 0x7D;
break;
case 7:
display = 0x07;
break;
case 8:
display = 0x7F;
break;
case 9:
display = 0x6F;
break;
}
wait(0.01);
GroundLeft = 1;
GroundRight = 0;
switch (rightnum)
{
case 0:
display = 0x3F;
break;
case 1:
display = 0x06;
break;
case 2:
display = 0x5B;
break;
case 3:
display = 0x4F;
break;
case 4:
display = 0x66;
break;
case 5:
display = 0x6D;
break;
case 6:
display = 0x7D;
break;
case 7:
display = 0x07;
break;
case 8:
display = 0x7F;
break;
case 9:
display = 0x6F;
break;
}
wait(0.01);
}
}
Why are you not following the reference code? https://os.mbed.com/docs/mbed-os/v5.9/reference/spislave.html
With SPI you have to understand that RX and TX happen at the same time and that the operation will take some amount of time.
.reply() sets up what to send, .receive() checks if something has been received (which probably won't be immediately), and .read() gets data from SPI controller.

Why doesn't this program detect that there is a whitespace?

So I was working on this program again, and I encountered another problem. I am testing if a character is a space. However, instead of detecting that the there is a space, it stops the loop and doesn't do anything more. Here is my code:
string reet(char reet) {
if (isspace(reet) == true) {
return "IA";
}
else {
switch (reet) {
case 'a':
return "Zg";
break;
case'b':
return "dA";
break;
case 'c':
return "dG";
break;
case 'd':
return "aw";
break;
case 'e':
return "bw";
break;
case 'f':
return "dQ";
break;
case 'g':
return "cg";
break;
case 'h':
return "ZA";
break;
case 'i':
return "cQ";
break;
case 'j':
return "YQ";
break;
case 'k':
return "eA";
break;
case 'l':
return "dw";
break;
case 'm':
return "cw";
break;
case 'n':
return "ag";
break;
case 'o':
return "eQ";
break;
case 'p':
return "bA";
break;
case 'q':
return "aA";
break;
case 'r':
return "ZQ";
break;
case 's':
return "cA";
break;
case 't':
return "Yw";
break;
case 'u':
return "eg";
break;
case 'v':
return "bg";
break;
case 'w':
return "aq";
break;
case 'x':
return "bQ";
break;
case 'y':
return "Yg";
break;
case 'z':
return "Zw";
break;
default:
return " ";
break;
}
}
}
string enc(string input) {
string sketchyBois = input;
string bigBoi = "";
int yeetL = sketchyBois.length() + 1;
for (int x = 0; x < yeetL;) {
bigBoi = bigBoi + reet(sketchyBois[x]);
x++;
}
return bigBoi;
}
I was just wondering if anyone can tell me why it is doing this? Thank you!
You need to change
if (isspace(reet) == true)
to
if (isspace(reet))
or
if (isspace(reet) != 0)
since isspace only returns a non-zero int value for a white space character, not a bool.
(Note that as a matter of coding style, it's generally preferred to omit comparison with true or false in boolean tests and just use if (expr) or if (!expr).)

array with same index changed without being reassigned

I am having trouble with this program. What it is intended to do is read a list of words, then take input for how long the word is, from the words of this length, count up the total of all the letters in them, sort them by highest frequency, and ask the user for the one with the highest frequency. Before it asks, it checks if that letter has already been asked be looping though the array prevguess. My problem is that, if I enter that 'yesletter' is true, the content of this array gets changed at the point after the inline comment "problem occurs here". The value of q within this test loop I put in doesn't change, but the value itself changes.
I know that the loop in main is infinite right now, but the program is not finished.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int i(0),n(0),counter(0),limit(0),length,mastercount(0);
int acount(0),bcount(0),ccount(0),dcount(0),ecount(0),fcount(0),gcount(0),hcount(0);
int icount(0),jcount(0),kcount(0),lcount(0),mcount(0),ncount(0),ocount(0),pcount(0);
int qcount(0),rcount(0),scount(0),tcount(0),ucount(0),vcount(0),wcount(0),xcount(0),ycount(0),zcount(0);
int letters[2][26];
char prevguess[26];
char words[60000][30];
void initarray() {
int len(0);
string line;
char temp;
ifstream wordlist ("words.txt");
if (wordlist.is_open())
{
while (wordlist.good())
{
getline (wordlist,line);
len=line.length();
for (n=0;n<30;n++)
{
if (n<len){
temp=line.at(n);
words[i][n]=temp;
}
else{
words[i][n]='*';
}
}
i++;
counter++;
}
}
else
{
cout<<"file not opened";
}
wordlist.close();
}
void selectlength()
{
int x(0),y(0);
bool shorter(false),longer(false);
cout <<"length of word"<<endl;
cin >> length;
limit=counter;
counter=0;
for (i=0;i<limit;i++){
shorter=false;
longer=false;
for (n=0;n<length;n++){
if (words[i][n]=='*')
{
shorter=true;
break;
}
}
if (words[i][length] != '*')
{
longer=true;
}
if (!longer && !shorter)
{
n=0;
for (y=0;y<30;y++)
{
if (n<length){
words[x][y]=words[i][n];
n++;
}
else{
words[x][y]='*';
}
}
x++;
counter++;
}
}
}
void mostletters(){
char temp;
for (i=0;i<counter;i++){
for (n=0;n<=length;n++){
temp=words[i][n];
switch (temp){
case 'a':
acount++;
break;
case 'b':
bcount++;
break;
case 'c':
ccount++;
break;
case 'd':
dcount++;
break;
case 'e':
ecount++;
break;
case 'f':
fcount++;
break;
case 'g':
gcount++;
break;
case 'h':
hcount++;
break;
case 'i':
icount++;
break;
case 'j':
jcount++;
break;
case 'k':
kcount++;
break;
case 'l':
lcount++;
break;
case 'm':
mcount++;
break;
case 'n':
ncount++;
break;
case 'o':
ocount++;
break;
case 'p':
pcount++;
break;
case 'q':
qcount++;
break;
case 'r':
rcount++;
break;
case 's':
scount++;
break;
case 't':
tcount++;
break;
case 'u':
ucount++;
break;
case 'v':
vcount++;
break;
case 'w':
wcount++;
break;
case 'x':
xcount++;
break;
case 'y':
ycount++;
break;
case 'z':
zcount++;
break;
}
}
}
}
void guessmost(){
int x,y,temp,temp2,q;
for (x=0;x<26;x++){
letters[0][x]=x;
switch (x){
case 0:
letters[1][x]=acount;
break;
case 1:
letters[1][x]=bcount;
break;
case 2:
letters[1][x]=ccount;
break;
case 3:
letters[1][x]=dcount;
break;
case 4:
letters[1][x]=ecount;
break;
case 5:
letters[1][x]=fcount;
break;
case 6:
letters[1][x]=gcount;
break;
case 7:
letters[1][x]=hcount;
break;
case 8:
letters[1][x]=icount;
break;
case 9:
letters[1][x]=jcount;
break;
case 10:
letters[1][x]=kcount;
break;
case 11:
letters[1][x]=lcount;
break;
case 12:
letters[1][x]=mcount;
break;
case 13:
letters[1][x]=ncount;
break;
case 14:
letters[1][x]=ocount;
break;
case 15:
letters[1][x]=pcount;
break;
case 16:
letters[1][x]=qcount;
break;
case 17:
letters[1][x]=rcount;
break;
case 18:
letters[1][x]=scount;
break;
case 19:
letters[1][x]=tcount;
break;
case 20:
letters[1][x]=ucount;
break;
case 21:
letters[1][x]=vcount;
break;
case 22:
letters[1][x]=wcount;
break;
case 23:
letters[1][x]=xcount;
break;
case 24:
letters[1][x]=ycount;
break;
case 25:
letters[1][x]=zcount;
break;
}
}
for (y=0;y<26;y++){
//problem occurs here (I think)
for (q=mastercount-1;q>=0;q--){
cout<<"for array index:"<<q;
cout << " the value of prevguess is "<<prevguess[q]<<endl;
}
for (x=26;x>=1;x--){
if (letters[1][x]>letters[1][x-1])
{
temp=letters[1][x-1];
letters[1][x-1]=letters[1][x];
letters[1][x]=temp;
temp2=letters[0][x-1];
letters[0][x-1]=letters[0][x];
letters[0][x]=temp2;
}
}
}
}
void letterguess(){
int x(0),z;
char guess;
bool goodletter(false),yesletter(false),alreadyguess(false);
while (!goodletter){
guess=letters[0][x]+97;
if (mastercount==0){
alreadyguess=false;
}
else{
for (z=mastercount-1;z>=0;z--){
if (guess==prevguess[z]){
alreadyguess=true;
}
}
}
if (!alreadyguess){
cout<<"is your letter "<< guess<<endl;
cin >> yesletter;
prevguess[mastercount]=guess;
}
if (yesletter && !alreadyguess){
goodletter=true;
}
else {
cout<<"wrong"<<endl;
x++;
}
mastercount++;
if (mastercount>26){
break;
}
}
}
int main() {
bool found(false);
initarray();
selectlength();
while (!found){
mostletters();
guessmost();
letterguess();
if (mastercount>26){
break;
}
}
}
I believe the problems start a bit lower than your comment.
for (x=26;x>=1;x--){
       if (letters[1][x]>letters[1][x-1])
When x is 26, letters[1][x] will be out of range.