我是开发领域的初学者,我面临着C ++语言中伪代码随机错误的问题。 我认为我的程序中的错误是: { srand(time(NULL)); }
请帮助我如何删除此错误和错误原因。 我开发的程序如下,
#include<iostream>
using namespace std;
main()
{
int lowerRange;
int upperRange;
lowerRange=1;
upperRange=1;
int secretNumber;
int guess;
guess=10;
cout<<"My Student ID is BC130400789 "<<endl;
cout<<"Enter lower range : ";
cin>>lowerRange;
cout<<"Enter upper range : ";
cin>>upperRange;
cout<<"Computer is calculating a random secret number in the given range...Done!"<<endl;
cout<<"\nPlease guesss the secret number in the range ["<<lowerRange<<" - "<<upperRange<<"]: ";
cin>>guess;
if(guess<10)
{
cout<<"You won! You guess the correct number.. ";
}
else
{
cout<<"Oooppsss...Your entered number is too high...Computer won"<<endl<<endl;
}
{ srand(time (NULL));}
secretNumber = rand()%10+1;
cout<<"Secret number was: "<<secretNumber<<endl<<endl;
}
system("pause");
}
答案 0 :(得分:1)
{}
不匹配。我还建议您阅读有关代码格式的内容。
答案 1 :(得分:0)
最后你有一个额外的括号。删除此项和system("pause");
,您将不会收到任何错误。另外main()
通常会返回int
,因此会int main()
。