-3

代码不会运行,说“返回值”是错误的,它说 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}; 
}
4

1 回答 1

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); 

然后,其余代码似乎在函数之外,这使编译器感到困惑。

于 2012-06-27T07:38:36.713 回答