[英]Having a simple issues. Don't know how to solve and I haven't seen any solutions online
These letters keep duplicating or changing one another:这些字母不断重复或更改:
|| a - u || e - y || w -c || v - b || x - d || z - f ||
I haven't been able to solve it by myself, or have seen a solution online.我自己无法解决,或者在网上看到了解决方案。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
char zodis[20];
char zodis2[25];
char h, ch;
int l, i, ng, n, k, x;
do{
cout << "\n\t\t ***** () Hangman () ***** \n\n\n\n";
cout << "\t\t Enter a word : ";
cin.get(zodis, 20);
l=strlen(zodis);
char pasir[20]="0";
n=0;k=0;
system("CLS");
for(i=0;i<=20;i++)
{
if (zodis[i]=='\0') {zodis2[i]='\0';break;}
if (zodis[i]!=' ') zodis2[i]='-';
}
ng=l+3;
do{
cia:
if (k!=0)
cout << "\n\n\t\t\t Chosen letters : " << pasir << "\n";
cout << "\n\n\n\t\t\t " << zodis2 << "\n\n\n Guesses left : "<< ng << ", choose the next letter : ";
cin >> ch;
system("CLS");
for ( i=0;i<25;i++ )
if ( pasir[i] == ch )
{
cout << "\t\t Raide : " << ch << " : jau pasirinkote\n";
goto cia;
}
ng--; pasir[k]=ch; pasir[k+1]=',';k+=2;
for (i=0;i<=20;i++)
if (zodis[i]==ch || zodis[i]==ch+20 || zodis[i]==ch-20) zodis2[i]=ch;
if (!strcmp(zodis2,zodis))
{
system("CLS");
cout << "\n\t\t\t " << string(zodis) << "\n\n\t\t\t Correct! :) \n" ; break;
}
}
while(ng > 0 || !strcmp (zodis2,zodis));
if (strcmp(zodis2,zodis))
cout << "\n The word was : " << string(zodis) << endl;
}
while (ch==0);
return 0;
}
Do you know how to use a debugger?你知道如何使用调试器吗? Probably time you learned.
大概是你学会的时间。 Anyway
反正
char zodis[20];
for(i=0;i<=20;i++)
... zodis[i] ...
Already that's an error, the valid indexes for zodis
are 0 to 19, so zodis[20]
is an out of bounds array access.这已经是一个错误,
zodis
的有效索引是 0 到 19,因此zodis[20]
是越界数组访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.