代码无法运行,表示“返回值”错误,表示返回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};
}
答案 0 :(得分:2)
好像你有一个额外的}
,它会过早地终止你的功能。
void main() {
srand(time(0)); //1-declare char letter=' ';
char guess[7];
char found[7]={letter};
int res=0;
char answer='Y';
} <--- This seems not correct
// 2-init
getarray(guess,7);
其余的代码似乎是在函数外部,这会使编译器感到困惑。