代码不会运行,说“返回值”是错误的,它说 return found[i]=letter
,并且srand time
也显示错误。我不确定如何解决?也许放入found[i]
并main()
放入return 1?
?并且不确定如何让其srand
正常工作?
#include <iostream>
using namespace std;
void getarray(char [], int);
void printa(char [],int );
void search(char [],int, char);
void main() {
srand(time(0)); //1-declare char letter=' ';
char guess[7];
char found[7]={letter};
int res=0;
char answer='Y';
}
//2-init
getarray(guess,7);
//3- processing
printa(guess,7);
while(answer == 'Y')
{
cout << "enter a letter";
cin >>letter;
search(guess,7,letter);
if (res != -1)
printa(found,7);
cout <<" do you want to continue(Y/N)?"<<endl;
cin >>answer;
}
//printing
system("pause");
}
void getarray(char a[], int n)
{
for(int i=0;i<n;i++)
a[i]= 65 + rand()%26;
}
void printa(char a[], int n)
{
for(int i=0;i<n;i++)
cout << " the letter " << i+1 << " is "<<a[i]<<endl;
}
void search(char a[],int n, char key)
{
for(int i=0;i<n;i++)
if ( a[i]== key)
return Found[i]=={letter};
}